Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GridBagLayout GUI is not displayed, this symbol is displayed instead

 
Roman Rodriguez
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have written a small application whose GUI is designed with GridBagLayout. It is, in fact, just a JTextArea into a JScrollPane. Just that.

When I execute my application in my computer, it looks ok. But after some time using it, sometimes the whole frame is empty and only shows this symbol:


Also, when I execute my application on a Windows 7 tablet (HP Slate), this happens always, just executing the application.

What does this means? Where is the problem?

My code is simple:
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Welcome to the Ranch!

You should create and show Swing windows/components only in the Event Dispatch Thread. Check this link which shows a sample program from the Oracle tutorial: sample.
You have to wrap the calls in a SwingUtilities.invokeLater().
 
Roman Rodriguez
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, so I understand, after reading about Initial Threads that I should create GUI elements like that, letting that work be done at the end by a thread which is going to be invoked when possible.

So, that symbol is appearing because my windows 7 tablet is single core and can't create gui then? It sounds right, but at my code I'm doing it at the beginning, so I don't understand how this problem appears in this particular case.
 
Nam Ha Minh
Ranch Hand
Posts: 502
Eclipse IDE Firefox Browser Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Roman,

You need to specify values for weightx and weighty properties of the gridbag constraints so that the component can be spanned horizontally and vertically. For example:
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem you are having usually happens when the window is resized so the component can't fit it so it "shrinks" (though your frame is set not to be resizeable, which confuses me now).
Try adding this:

in createGUI() method, after you set gridx/gridy of your GridBagConstraints instance.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic