• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to change border color of grid layout in a panel  RSS feed

 
chanakya nani
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Guys, My problem is that although i create a grid in a panel and add labels to it i cant see them when i run the program....i think it is being camouflaged,please tell me how to change the border colors of that grid in order to see it.


 
Frederick Winsnes
Greenhorn
Posts: 17
Android Chrome Eclipse IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I must admit that I am no Java-expert, but isn't it better to do "frame.setVisible(true);" the last thing in the code?
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chanakya nani wrote:Guys, My problem is that although i create a grid in a panel and add labels to it i cant see them when i run the program...


As far as I can see you only add one label to the panel.

(And I agree that you should call setVisible(true) after setting up the GUI, not halfway through the process.)
 
Rob Spoor
Sheriff
Posts: 20904
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frederick (welcome!) is right. After you display a window like a JFrame or JDialog, you must inform the user interface to update itself after making changes by calling revalidate() and repaint() on the JComponent you added a component to. If it's not a JComponent, revalidate() does not exist and you use invalidate() instead.

I'll move this thread to the UI forum (unless someone beats me to it ).

Also, the add(String, Component) method shouldn't be used anymore, as specified in the Javadocs. Use getContentPane().add(panel, BorderLayout.CENTER) instead. And since Java 5.0 you can even skip the call to getContentPane(): frame.add(panel, BorderLayout.CENTER) will no longer throw an error.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!