1

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
fuLLMetaLMan
  • 165
  • 4
  • 17
  • 2
    this in Swing can be everything that is actually declared `mywhatever extend something` in current JVM, for better help sooner post an [SSCCE](http://sscce.org/), short, runnable, compilable, – mKorbel May 05 '13 at 21:09
  • I have also tried with (myJFrame, "text") but doesn't help either. Its just so weird, because it worked a couple of days ago. – fuLLMetaLMan May 05 '13 at 21:14
  • 3
    If it worked before then you are obviously doing something different now. Compare your old code to see what is different. You didn't post your SSCCE so we can't help since we are not mind readers. – camickr May 05 '13 at 21:26
  • Yeah i know, sorry. My code is so big right now that I cant seem to produce a small compilable test of my problem. I was just wondering if anyone had experienced this before and had some tips. I'm pretty new to Java so theres alot i dont know. – fuLLMetaLMan May 06 '13 at 11:06

1 Answers1

2
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.

Keerthivasan
  • 12,760
  • 2
  • 32
  • 53