Question

This is driving me crazy: I programmed a small JFrame with several JPanels inside. I have several error messages that I have created with

 JOptionPane.showMessageDialog(this, "Text here");

But it always, no matter what, centers in the middle of the screen, and NOT the program-window. It worked for a long time, and suddenly, after a weekend I came back and now it wont center-align inside the window. Any ideas? anyone?

public class kontrollvindu1 extends JPanel    {

public Kontrollvindu1()  {
    showMsg("text here");
}
public void showMsg(String text)    {
    JOptionPane.showMessageDialog(this, text);
}

}//END OF CLASS Kontrollvindu1
Was it helpful?

Solution

JOptionPane.showMessageDialog(this, "Text here");

In my experience if you replace the this call with null it will center on the screen. If you replace the this call with panel it should center on the panel. But I've only made this work on a JFrame, I haven't build a JPanel yet.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top