Note that there are some explanatory texts on larger screens.

plurals
  1. PONon-modal JDialog not displaying content?
    text
    copied!<p>I am building a server program that receives a socket connection from a client. When the program initiates the server, I would like to display a dialog that displays "Waiting for connection..." as it waits. Once the connection is received, I would like to programatically close the window. As I do not want to block the execution of the program as it waits for the socket connection, I have used a non-modal dialog to display the message. This works, except that the dialog does not display the text that I would like it to. The dialog title displays fine, but the message pane does not. Why is this? I have tried several different ways to accomplish this, including the code below, all to no avail.</p> <pre><code>public class AboutDialog extends JDialog implements ActionListener { public AboutDialog(JFrame parent, String title, String message) { super(parent, title, false); if (parent != null) { Dimension parentSize = parent.getSize(); Point p = parent.getLocation(); setLocation(p.x + parentSize.width / 4, p.y + parentSize.height / 4); } JPanel messagePane = new JPanel(); messagePane.add(new JLabel(message)); getContentPane().add(messagePane); setDefaultCloseOperation(DISPOSE_ON_CLOSE); pack(); setLocationRelativeTo(null); setVisible(true); } public void actionPerformed(ActionEvent e) { setVisible(false); dispose(); } } </code></pre> <p>Just in case my explanation isn't clear, I pass "Waiting for connection..." into the AboutDialog constructor as the message parameter. Thanks for any guidance!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload