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

1.3.0_002 Once hidden component can not get paint focus automatically

XMLWordPrintable

    • 04
    • x86
    • windows_nt
    • Verified

      This is originally reported as 4343423 and it still occurred with JDK1.3.0_002.

      1. Configration

        1) JDK ver.
           java version "1.3.0_02"
           Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0_02)
           Java HotSpot(TM) Client VM (build 1.3.0_02, mixed mode)
        2) OS
           Windows NT 4.0(SP5) Japanese Edition

      2. Behavior & Reproduction

       UI components which are completely hidden by a frame in front do not
       reflect any changes made to them when the frame is closed
       and they become visible.

       1) Compile and run the DemoApp file. A BackFrame appears with a JTextField,
          JList and JButton.
       2) Click the 'Show Frame' button to create a FrontFrame which completely hides
          the BackFrame.
       3) Click the 'Set Hidden Text' button in the FrontFrame to set the JTextField to "Some Text" and to add "Some Text" to the JList.
       4) Close the FrontFrame.

          With ladybird and Merlin build, the following demo program worked well.
          With 1.3.0_002, the JTextField and JList remain blank until another
          repaint is forced such as when the BackFrame is minimized then restored.

      3. Sample code

      Source code follows: DemoApp.java

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

      public class DemoApp
      {
      boolean packFrame = false;

      public DemoApp()
      {
      BackFrame frame = new BackFrame();
      if (packFrame)
      frame.pack();
      else
      frame.validate();
      frame.setVisible(true);
      }

      public static void main(String[] args)
      {
      try
      {

      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
      }
      catch(Exception e)
      {
      }
      new DemoApp();
      }
      }

      class BackFrame extends JFrame
      {
      JTextField jTextField1 = new JTextField();
      JButton jButton_SHOW_FRAME = new JButton();
      JList jList1 = new JList();
      BorderLayout borderLayout1 = new BorderLayout();
      DefaultListModel model = new DefaultListModel();

      public BackFrame()
      {
      enableEvents(AWTEvent.WINDOW_EVENT_MASK);
      try
      {
      this.getContentPane().setLayout(borderLayout1);
      this.setSize(new Dimension(300, 300));
      this.setTitle("Demo Frame");
      jButton_SHOW_FRAME.setText("Show Frame");
      jButton_SHOW_FRAME.addActionListener(new
      java.awt.event.ActionListener()
      {
      public void actionPerformed(ActionEvent e)
      {
      jButton_SHOW_FRAME_actionPerformed(e);
      }
      });
      jTextField1.setPreferredSize(new Dimension(100, 22));

      jList1.setBorder(BorderFactory.createLineBorder(Color.black));
      jList1.setModel(model);
      this.getContentPane().add(jTextField1,
      BorderLayout.NORTH);
      this.getContentPane().add(jList1, BorderLayout.CENTER);
      this.getContentPane().add(jButton_SHOW_FRAME,
      BorderLayout.SOUTH);
      }
      catch(Exception e)
      {
      e.printStackTrace();
      }
      }

      protected void processWindowEvent(WindowEvent e)
      {
      super.processWindowEvent(e);
      if(e.getID() == WindowEvent.WINDOW_CLOSING)
      {
      System.exit(0);
      }
      }

      void jButton_SHOW_FRAME_actionPerformed(ActionEvent e)
      {
      // create and show the front frame which hides the back frame
      FrontFrame frontFrame = new FrontFrame(this);
      frontFrame.setSize(400,400);
      frontFrame.setVisible(true);
      }

      public void addText(String text)
      {
      // called by the front frame to set the textfield text and
      // add text to the list while the back frame is hidden
      jTextField1.setText(text);
      model.addElement(text);
      }
      }


      class FrontFrame extends JFrame
      {

      private BackFrame backFrame;

      JButton jButton_SET_TEXT = new JButton();
      JButton jButton_CLOSE = new JButton();
      FlowLayout flowLayout1 = new FlowLayout();

      public FrontFrame(BackFrame frame)
      {
      backFrame = frame;
      try
      {
      jButton_SET_TEXT.setText("Set Hidden Text");
      jButton_SET_TEXT.addActionListener(new
      java.awt.event.ActionListener()
      {
      public void actionPerformed(ActionEvent e)
      {
      jButton_SET_TEXT_actionPerformed(e);
      }
      });
      jButton_CLOSE.setText("Close");
      jButton_CLOSE.addActionListener(new
      java.awt.event.ActionListener()
      {
      public void actionPerformed(ActionEvent e)
      {
      jButton_CLOSE_actionPerformed(e);
      }
      });
      this.getContentPane().setLayout(flowLayout1);
      this.setTitle("Front Frame");
      this.getContentPane().add(jButton_SET_TEXT, null);
      this.getContentPane().add(jButton_CLOSE, null);
      }
      catch(Exception e)
      {
      e.printStackTrace();
      }
      }

      void jButton_SET_TEXT_actionPerformed(ActionEvent e)
      {
      // set the text in the hidden (back) frame
      backFrame.addText("Some Text");
      }

      void jButton_CLOSE_actionPerformed(ActionEvent e)
      {
      this.setVisible(false);
      }
      }

      =============================================================================

            ehawkessunw Eric Hawkes (Inactive)
            tbaba Tadayuki Baba (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: