I currently have a JDialog
created by calling the createDialog()
method from my instance of JOptionPane
:
JOptionPane pane = new JOptionPane(myPanel, JOptionPane.PLAIN_MESSAGE,JOptionPane.DEFAULT_OPTION, null, new Object[]{}, null);
dialog = pane.createDialog(null, "");
I wanted to be able to remove the title bar from the JDialog
by calling setUndecorated(true)
onto the JDialog
, but I get an IllegalComponentStateException: The dialog is displayable
exception when I attempt to run my program.
As far as I know, the dialog is not being displayed before I call dialog.show()
, which leads me to believe that the dialog is indeed "displayable" upon instantiating the dialog through pane.createDialog()
far beyond my understanding of the JDialog
API.
I have attempted to call setVisible(false)
prior to using setUndecorated(true)
, but to no avail.
Any help would be appreciated as to how or of it is possible at all to remove the title bar of a JDialog
of this type. Removing the title bar from a normal JDialog
is easy enough, as seen from numerous other answers to questions of this type, but I cannot seem to get it to work for a JDialog
created through createDialog()
.
Relevant code:
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();
See Question&Answers more detail:
os