当我使用createDialog()
时,如何删除OK按钮(我需要使用createDialog,因为我需要设置位置)
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);
答案 0 :(得分:0)
JOptionPane.showOptionDialog(null, "Hello world","No button?", JOptionPane.DEFAULT_OPTION,JOptionPane.INFORMATION_MESSAGE, null, new Object[]{}, null);
我想这应该有帮助
答案 1 :(得分:0)
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);
在你的情况下会是这样的:
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);
经过测试和工作。