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

An AWT modalless dialog box with lightweight components makes background damaged

    XMLWordPrintable

    Details

      Description

      I mixed a heavyweight dialog box and lightweight components. All of sundden, the background of the dialog box is so mess. It seems like it fetches an image from outside of the box and draws on its background. It's unreadible.
      Here is the test case. Windows95 + JDK1.2Beta1 + Swing-0.5.1

      1) Test.java
      import java.awt.*;
      import java.io.*;
      import java.util.*;
      import java.awt.event.*;
      import com.sun.java.swing.*;

      public class Test extends JFrame implements ActionListener
      {
          JButton testButton, dialogButton;

          public Test(){
              super("Test Suite");

              testButton = new JButton("test");
              testButton.addActionListener(this);

              add(testButton);
      pack();
              show();
          }

          public void actionPerformed(ActionEvent e){
              SimpleDialog dialog = new SimpleDialog(this);
          }

          public static void main(String args[]){
              Test frame = new Test();
          }
      }

      // The end.

      2) SimpleDialog.java
      import com.sun.java.swing.*;
      import com.sun.java.swing.text.*;

      import java.awt.*;
      import java.awt.event.*;
      import java.util.*;
      import java.io.*;


      public class SimpleDialog extends Dialog
      {
          JLabel label;
          JPanel upperPanel;
          JPanel lowerPanel;
          JTextField textField = null;


          public SimpleDialog(Test frame){
              super(frame, "Open a cassette...", false);
              label = new JLabel("Open: ");

              compose();
              setSize(300,150);
              setVisible(true);
          }

          private void compose(){
              // upper panel
              //***********************************************************
              Component comp1 = Box.createRigidArea(new Dimension(20, 1));
              Component comp2 = Box.createRigidArea(new Dimension(20, 1));
              Component comp3 = Box.createRigidArea(new Dimension(1, 20));
              Component comp4 = Box.createRigidArea(new Dimension(1, 20));

              upperPanel = new JPanel(true);

              upperPanel.setLayout(new BorderLayout());
              upperPanel.add("East" , comp1);
              upperPanel.add("West" , comp2);
              upperPanel.add("South", comp3);
              upperPanel.add("North", comp4);

              Box labeledText = Box.createVerticalBox();

              labeledText.add(label);
              textField = new JTextField();
              labeledText.add(textField);

              upperPanel.add("Center", labeledText);

              // lower panel
              //***********************************************************
              lowerPanel = new JPanel(true);
              lowerPanel.setLayout(new FlowLayout(FlowLayout.CENTER));

              JButton cancel = new JButton("Close");
              cancel.setActionCommand("close");
              cancel.addActionListener(buttonListener);
              lowerPanel.add(cancel);

              add("Center", upperPanel);
              add("South", lowerPanel);
          }

          ActionListener buttonListener = new ActionListener(){
              public void actionPerformed(ActionEvent e){
                  setVisible(false);
              }
          };

          public void setVisible(boolean b) {
           int x, y;
           Rectangle bounds = getParent().getBounds();
           Rectangle abounds = getBounds(); // bounds() was depreciated.

              // move was depreciated
              x = bounds.x + (bounds.width - abounds.width)/ 2;
              y = bounds.y + (bounds.height - abounds.height)/2;

           if(x>0 && y>0) setLocation(x, y);
           else setLocation(300, 200);

              super.setVisible(b);
          }

      }

      // The end of the file. Kim Bae-Chul

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              sswingtrsunw Swingtraq Swingtraq (Inactive)
              Reporter:
              bkimsunw Bae-chul Kim (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: