我目前有一个通过从我的实例JDialog
调用方法创建的:createDialog()
JOptionPane
JOptionPane pane = new JOptionPane(myPanel, JOptionPane.PLAIN_MESSAGE,JOptionPane.DEFAULT_OPTION, null, new Object[]{}, null);
dialog = pane.createDialog(null, "");
我希望能够JDialog
通过调用来从 中删除标题setUndecorated(true)
栏JDialog
,但是IllegalComponentStateException: The dialog is displayable
当我尝试运行我的程序时出现异常。
据我所知,在我调用之前没有显示对话框dialog.show()
,这让我相信在实例化对话框时对话框确实是“可显示的”,pane.createDialog()
远远超出了我对JDialog
API 的理解。
我曾尝试setVisible(false)
在使用之前致电setUndecorated(true)
,但无济于事。
JDialog
关于如何或完全可以删除这种类型的标题栏的任何帮助将不胜感激。从此类问题的许多其他答案中可以看出,从正常中删除标题栏JDialog
很容易,但我似乎无法让它为JDialog
创建的createDialog()
.
相关代码:
input= new JTextField(50);
input.addKeyListener(new ConsoleKeyListener());
input.addAncestorListener( new RequestFocusListener() );
field = new JTextArea();
field.setEditable(false);
field.setLineWrap(true);
JScrollPane area = new JScrollPane(field, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
field.setRows(10);
field.setText(consoleText);
JPanel myPanel = new JPanel();
myPanel.setLayout(new BorderLayout(0,0));
myPanel.add(input, BorderLayout.PAGE_END);
myPanel.add(area, BorderLayout.PAGE_START);
input.setFocusable(true);
input.requestFocus();
int result = 101;
//int result = JOptionPane.showOptionDialog(null, myPanel,"", JOptionPane.DEFAULT_OPTION,JOptionPane.PLAIN_MESSAGE, null, new Object[]{}, null);
JOptionPane pane = new JOptionPane(myPanel, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, null, new Object[]{}, null);
dialog = pane.createDialog(null, "");
dialog.setVisible(false);
dialog.setUndecorated(true);
//dialog.undecorated = true;
//dialog.setOpacity(0.55f);
removeMinMaxClose(dialog);
removeMinMaxClose(pane);
removeMinMaxClose(myPanel);
dialog.getRootPane().setOpaque(false);
//JDialog dialog = new JDialog();
//dialog.setVisible(false);
//dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
//myPanel.setUndecorated(true);
//dialog.setUndecorated(true);
//dialog.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
//dialog.setBounds( 100, 100, 300, 200 );
dialog.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.out.println("yo");
}
});
dialog.setVisible(true);
dialog.show();