简体   繁体   中英

Create dialog with no buttons

How do I remove the OK button when I use createDialog()

(I need to use createDialog because I need to set the location)

        JPanel myPanel = new JPanel();
        myPanel.setLayout(new BoxLayout(myPanel, BoxLayout.Y_AXIS));//new BorderLayout());
        myPanel.setPreferredSize(new Dimension(400,400));
        JTextField tf= new JTextField(50);
        tf.setText("<HTML>Here is<br>my text");
        myPanel.add(tf);

        JOptionPane optionPane = new JOptionPane(myPanel,1,JOptionPane.DEFAULT_OPTION);   
        optionPane.setOptions(new Object[]{});
        JDialog dialog = optionPane.createDialog(null, "Quick Help");

                dialog.setLocation(10,10);
        dialog.setAlwaysOnTop(dialog.isAlwaysOnTopSupported());
        dialog.setVisible(true);
JOptionPane.showOptionDialog(null, "Hello world","No button?", JOptionPane.DEFAULT_OPTION,JOptionPane.INFORMATION_MESSAGE, null, new Object[]{}, null);

我想这应该有所帮助

JOptionPane pane = new JOptionPane("message",  JOptionPane.PLAIN_MESSAGE, JOptionPane.PLAIN_MESSAGE);
            JDialog myDialog=  pane.createDialog(null, "New Topic");
            myDialog.setLocation(1000, 100);
            myDialog.setVisible(true);

In your case would be something like this:

   JOptionPane optionPane = new JOptionPane(this,1,JOptionPane.PLAIN_MESSAGE);   
                optionPane.setOptions(new Object[]{});
                JDialog dialog = optionPane.createDialog(null, "Quick Help");

                dialog.setLocation(1000,10);
                dialog.setAlwaysOnTop(dialog.isAlwaysOnTopSupported());
                dialog.setVisible(true);

Tested and working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM