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

JOptionPane-passing Component as param 'message' doesn't show Component properly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.2.0
    • client-libs

      When a Component is passed as a pramaeter for 'message' param, it is not displayed properly in the JOPtionPane. In the sample code given below, a JPanel is passed for param 'message'. The JPanel is displayed and so also a shadow of the JPanel which should not be there. This is seen on Win NT and Solaris. It alos fails for the latest nightly build picked up on 02/05/98

      Steps to reproduce the same,
      1. Run the application.
      2. Click on the button - 'OptionPane with message as String'. - The OptionPane is displayed properly.
      3. Click on the button - 'OptionPane with message as Component'. - The Component is not displayed properly.


      Sample Code is provided below to simulate the same,


      -- Sample Code --

      import java.util.*;
      import java.awt.*;
      import java.awt.event.*;
      import com.sun.java.swing.*;



      public class TestJOPane03 extends JFrame implements ActionListener {
      /*************************************** Bug Description ***************************************/

      String[] strBugDesc = { "",
      "",
      "",
      "",
      "This TestCase tests the JOptionPane Component",
      "**Problem** : When the message parameter is a Component,",
      "the Component should be displayed in the JOptionPane. ",
      "The Component is not being displayed properly",
      "",
      "Steps to reproduce :",
      "1. Click on the button - 'OptionPane with message as String'. - The OptionPane is displayed properly.",
      "2. Click on the button - 'OptionPane with message as Component'. - The Component is not displayed properly.",
      " A shadow of the component is displayed",
      "",
      "Pass/Fail Criteria : ",
      "Pass -- The Component should be displayed properly.",
      "",
      "",
      "",
      ""};
        /*************************************** Bug Description ***************************************/

      Container content;
      JPanel panel;
      JButton bn;

      TestJOPane03(String[] args) {
      displayBugDesc();
      content = getContentPane();
      content.setLayout(new BorderLayout());
      addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent event){
      System.exit(0);
      }
      }
      );
      panel = new JPanel();
      panel.setLayout(new FlowLayout());


      panel.add(bn = new JButton("OptionPane with message as String"));
      bn.setActionCommand("String");
      bn.addActionListener(this);

      panel.add(bn = new JButton("OptionPane with message as Component"));
      bn.setActionCommand("Component");
      bn.addActionListener(this);

      content.add("Center", panel);
      pack();
      show();
      }


      public void actionPerformed(ActionEvent e) {
      if(e.getActionCommand().equals("String")) {
      String str = "This is an OptionPane with String";
      JOptionPane.showMessageDialog(null, str);
      }

      else if(e.getActionCommand().equals("Component")) {
      JPanel p = new JPanel();
      p.add(new JButton("TestButton"));
      p.add(new JButton("Another TestButton"));
      p.add(new JLabel("This is an OptionPane with Components"));

      JOptionPane.showMessageDialog(null, p);
      }
      }

      public void displayBugDesc() {
      int n = strBugDesc.length;
      System.out.println("/******************************* Bug Description and Comments *******************************/");
      System.out.println();
      for(int i = 0; i < n; i ++) {
      System.out.println(strBugDesc[i]);
      }
      System.out.println();
      System.out.println("/******************************* Bug Description and Comments *******************************/");
      }



      // Main funtion
      public static void main(String[] args) {
      TestJOPane03 test = new TestJOPane03(args);
      }
      }


      -- Sample Code --

            amfowler Anne Fowler (Inactive)
            mmadhugisunw Mukund Madhugiri (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: