• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable Cell renderer causing program to go black when minimized

 
Jem Smith
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my first time posting here and I'm new to java so any help is appreciated.

I'm making a program that selects classes from a database via a jcombo box and then populates a time table with the class times.

I've used a custom cellrenderer that extends DefaultTableCellRenderer to text wrap the information and change the background of the cells.

It works but when i minimize the program it goes all black and if I double click I get a new JTextArea opening up on the timetable and when I minimize the program and go to open it again i get an "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException" and the cell render seems to be called again even though i haven't rerun the program.

This is the cell renderer that I built


and this code will show you an example of the error in action I hope;



 
Rob Camick
Ranch Hand
Posts: 2700
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i get an "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException"


So did you look at the line causing the NPE? The message tells you the line causing the problem. In your case its:



This tells me that a cell in your table is null. It is the the toString() representation that is important it is the Object in the TableModel that is important. So the code should be:



Also you don't need:


the JTable will look after the size and Swing components are visible by default (except for top level containers like JFrame).
 
Jem Smith
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That worked! Can't believe it was that simple, thank you very much, you are a star!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!