Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4287208

setEnabledAt doesn't re-calc bounds of Tab if Icon doesn't exists at creation

XMLWordPrintable

    • beta2
    • sparc
    • solaris_2.6

      Switching between setEnabledAt(index,[true/false] does not revalidate the tab if the tab does not originally have an Icon associated with it, but does have a disabledIcon. Resizing the Application makes the Tab resize to fit text and disabled icon, or clicking the
      other Tab will cause a re-calculate of Tab bounds. Otherwise the
      icon is added and the text becomes grayed out but drawn across the next Tab

      Compile test below and keep pressing blue "Test 1" button. Watch the application
      and it will be clear as to what the bug is. If not please Call: ###@###.### x22234
       
      TestCase:

      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import javax.swing.border.*;
      import javax.accessibility.*;

      public class SetDisabledIconAt extends JFrame implements ActionListener{
        String path;
        boolean state = true;
        Container contentPane = getContentPane();
        JTabbedPane jtp = new JTabbedPane();
        JPanel panelOne = new JPanel();
        JPanel panelTwo = new JPanel();
        
        private JPanel buttonPanel = new JPanel();
        private JPanel bottomPanel = new JPanel(new BorderLayout());
        private JPanel statusPanel = new JPanel();
        Object obj;
        
        private JLabel label = new JLabel("Press Blue \"Test 1\" button to start test.");
        private JButton start, start1, start2, start3;
        private JButton pass;
        private JButton fail;

        SetDisabledIconAt(String workDir) {
          super("setDisabledIconAt() Test");

          // Add Invoke Buttons
          start = addButton(buttonPanel,"Test 1",Color.blue);
          pass = addButton(buttonPanel,"Pass",Color.green);
          fail = addButton(buttonPanel,"Fail",Color.red);
          bottomPanel.add(buttonPanel,BorderLayout.NORTH);
          statusPanel.add(label);
          bottomPanel.add(statusPanel,BorderLayout.SOUTH);

          contentPane.add(bottomPanel,BorderLayout.SOUTH);
          // Add all the Tabs to your TabbedPane
          jtp.add("Panel One", new JPanel());
          //jtp.addTab("Panel One",new ImageIcon(workDir+"/rocketsm.gif"), new JPanel());
          jtp.addTab("Panel Two",new ImageIcon(workDir+"/rocketsm.gif"), new JPanel());
          //jtp.add("Panel Three", new JPanel());
          // jtp.add("Panel Four", new JPanel());
          // jtp.add("Panel Five", new JPanel());
          // jtp.add("Panel Six", new JPanel());
          contentPane.add(jtp,BorderLayout.CENTER);

          Icon icon1 = jtp.getIconAt(1);
          // Below line is for null icon to be drawn no recalculation needs to be done.
          //jtp.setDisabledIconAt(0,null);
          // Below line requires recalculation of tab because there is a disabled icon assocciated with it.
          jtp.setDisabledIconAt(0,icon1);

          // These next two lines add a diabled icon to tab 2
          //Icon icon2 = jtp.getDisabledIconAt(0);
          //jtp.setDisabledIconAt(1,icon2);
        
          // Add Window handler
          addWindowListener(new WindowAdapter(){
            public void windowClosing(WindowEvent event){ System.exit(0);}
          });
        }

        public void actionPerformed(ActionEvent evt) {
          String cmd = evt.getActionCommand();
          if (evt.getSource() == pass) {
            System.out.println("Test Passed");
            System.exit(0);
          }
          else if (evt.getSource() == fail) {
            System.out.println("Test Failed");
            System.exit(1);
          }
          else if (evt.getSource() == start) {
            jtp.setEnabledAt(0,state);
            jtp.setEnabledAt(1,!state);
            label.setText("Icon1 disabled="+jtp.isEnabledAt(0)+" Icon2 disabled="+jtp.isEnabledAt(1));
            if(state)
      state = false;
            else
      state = true;
          }
        }
        
        public JButton addButton(JPanel addComponent, String name, Color color) {
          JButton b = new JButton(name);
          b.setBackground(color);
          b.addActionListener(this);
          addComponent.add(b);
          return b;
        }

        public static void main(String[] args) {
           String workDir = "";
          if (args.length != 0)
            workDir = args[0];
          else
            workDir = System.getProperty("user.dir");
          // Launch Test with workDir location. Location to find gif files.
          SetDisabledIconAt t = new SetDisabledIconAt(workDir);
          t.setSize(500,170);
          t.setVisible(true);
        }
      }

            amfowler Anne Fowler (Inactive)
            collins Gary Collins (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: