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

JTabbedPane in java.awt.Frame, only component on the first tab is displayed

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      beta
    • CPU:
      x86, sparc
    • OS:
      solaris_2.6, windows_nt

      Description



      Name: clC74495 Date: 02/25/99


      This is a problem with JDK1.1.6 to JDK1.2.
      To run this, compile this file, then point the java interpreter at it:
      "java TestPanel".

      Thanks.
      Bill

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

      public class TestPanel extends Frame implements ActionListener {

        public static String TITLE = "Testing Swing";

        JTabbedPane psetsPane = new JTabbedPane();
        JPanel buttonPanel = new JPanel();

        public TestPanel (String tabs[]) {

          for (int i = 0; i < tabs.length; i++) {
            psetsPane.addTab (tabs[i], new JLabel(tabs[i]));
          }
          add(psetsPane, BorderLayout.NORTH);

          JButton testButton = new JButton("Test");
          buttonPanel.add(testButton, BorderLayout.CENTER);
          testButton.setActionCommand("Test");
          testButton.addActionListener(this);

          JButton quitButton = new JButton("Quit");
          buttonPanel.add(quitButton, BorderLayout.CENTER);
          quitButton.setActionCommand("Quit");
          quitButton.addActionListener(this);

          add(buttonPanel, BorderLayout.SOUTH);
          pack();
        }

        public void actionPerformed(ActionEvent e) {

          if (e.getActionCommand().equals("Quit")) {
            System.exit(0);

          } else if (e.getActionCommand().equals("Test")) {
            int tabcount = psetsPane.getTabCount();
            for (int i = 0; i < tabcount; i++) {
      JLabel c = (JLabel) psetsPane.getComponentAt(i);
      System.out.println("Pane " + i + ": Label="+c+" ("+c.getText()+")");
            }
          };
        }

        public static void main(String args[]) {
          String tabs[] = { "one", "two", "three" };

          TestPanel tp = new TestPanel (tabs);
          tp.setVisible(true);
        }
      }
      (Review ID: 54534)
      ======================================================================

      Name: skT88420 Date: 08/06/99


      jTabbedPane doesn't always show the correct pane when a tab is
      selected. I don't know if I am not using it right, but if I don't
      handle stateChanged events myself, the correct pane is not updated
      until the window is resized. Regardless of the tab that is selected
      the same button is always showing. When I do catch the stateChanged
      events and validate and repaint, it behaves correctly except after
      resizing the window. After a resize, the next tab selection is
      not repainted correctly even though the correct tab is highlighted,
      and the stateChanged event is received. This is from jdk 1.2.2
      Classic VM (build JDK-1.2.2-W, native threads symcjit)


      public class TestTabFrame extends java.awt.Frame {
        public TestTabFrame() {
          initComponents ();
          pack ();
        }
        private void initComponents () {
          addWindowListener (new java.awt.event.WindowAdapter () {
              public void windowClosing (java.awt.event.WindowEvent evt) {
                exitForm (evt);
              }
            }
          );
          setLayout (new java.awt.BorderLayout ());
          jTabbedPane1 = new javax.swing.JTabbedPane ();
          jTabbedPane1.addChangeListener (new javax.swing.event.ChangeListener () {
              public void stateChanged (javax.swing.event.ChangeEvent evt) {
                jTabbedPane1StateChanged (evt);
              }
            }
          );
            jButton1 = new javax.swing.JButton ();
            jButton1.setText ("jButton1");
            jTabbedPane1.addTab ("jButton1", jButton1);

            jButton2 = new javax.swing.JButton ();
            jButton2.setText ("jButton2");
            jTabbedPane1.addTab ("jButton2", jButton2);

          add (jTabbedPane1, "Center");

        }

        private void jTabbedPane1StateChanged (javax.swing.event.ChangeEvent evt) {
          jTabbedPane1.validate();
          jTabbedPane1.repaint();
        }
        private void exitForm(java.awt.event.WindowEvent evt) {
          System.exit (0);
        }


      // Variables declaration - do not modify
        private javax.swing.JTabbedPane jTabbedPane1;
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
      // End of variables declaration


        public static void main(java.lang.String[] args) {
          new TestTabFrame ().show ();
        }

      }
      (Review ID: 93625)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              amfowler Anne Fowler (Inactive)
              Reporter:
              clucasius Carlos Lucasius (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: