Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JComboBox crashes application  RSS feed

 
Will Ashton
Greenhorn
Posts: 22
Java Mac Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi programmers,

I lately started using "advanced" Swing-Components, like JTabbedPane and JComboBox, but I dont get the ComboBox working
This is the code I use:



"PreferencesPanel" is placed inside a TabbedPane:



The TabbedPane is placed in another JPanel, which is placed in an Fullscreen-Window. The code for this should be ok and contains nothing harmful, but if you still want to see it, I can post it later.

Now, the problem is, that when I start the application and open the "Preferences"-Tab, everything seems normal, I can see the ComboBox and the first entry is selected. But when I click it, instead of opening and offering me more choices, the program crashes and my screen turns black (I'm using OS X, on Windows it would possibly turn white, but I didnt test this out).
Can anybody help me with this?
 
Campbell Ritchie
Sheriff
Posts: 53720
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens if you add the combo box to a frame directly?
Can you wrap the whole application in a try-catch and print the stack traces? If you cannot see the stack traces, write them to a text file and examine that text file when you reboot your system.
What is a MapEditWindow and how are you using it in your panel class?
 
Will Ashton
Greenhorn
Posts: 22
Java Mac Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote a small test-program which just added a ComboBox to a frame. It worked, but it is not an option for the main program.
I dont really know how to print the stack traces, can you give me a hint/link?
MapEditWindow is the name of the Fullscreen-Frame, which works as the basis for the application. Nearly all classes inside the application need it at some point, so I decided to include it in every constructor.

Edit:
Oops, I forgot to mention, that there are no error-messages or exceptions
 
Campbell Ritchie
Sheriff
Posts: 53720
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Printing the StackTrace is a normal part of Exception handling. If you are not familiar with it you should go through that link.

You can try a text file, because you obviously want a quick solution.If the errors.txt file appears, we might be onto something. If it doesn't we shall have to think again.
 
Campbell Ritchie
Sheriff
Posts: 53720
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will Ashton wrote: . . .
Oops, I forgot to mention, that there are no error-messages or exceptions
In which case we shall have to think again.

Reduce the size of your app and gradually add Components back until something goes wrong.
 
Campbell Ritchie
Sheriff
Posts: 53720
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will Ashton wrote: . . .
MapEditWindow is the name of the Fullscreen-Frame, which works as the basis for the application. . . .
Probably not the cause of the screen going black, but that ain't a good idea. You should use the frame for display purposes and nothing else. Your logic should be indifferent classes. The display classes do not need the logic. It is the other way round. The logic classes should be able to operate on their own, but they need the display classes for showing their results.

What resolution screen have you got? Are you actually setting the resolution, because that may cause the screen to go blank if you get it wrong?
 
Will Ashton
Greenhorn
Posts: 22
Java Mac Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im already at minimum application size. The only thing I could delete is the ComboBox itself, which obviously "solves" the problem.
My screen resolution is 1280x800, but its not changed by the app yet. The resolution values are just Strings.
Could the problem have to do something with the actionPerformed ()?
 
Campbell Ritchie
Sheriff
Posts: 53720
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No idea, sorry. We might as well see the actionPerformed method.

I think I am running out of ideas here. Sorry. Anybody else got any ideas?
 
Tony Docherty
Bartender
Posts: 3195
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:No idea, sorry. We might as well see the actionPerformed method.

I think I am running out of ideas here. Sorry. Anybody else got any ideas?

I agree that we need to see the code for all listeners you have added to the JCombobox. My guess is something in one of the listeners is causing the problem and hiding the exception.
 
Will Ashton
Greenhorn
Posts: 22
Java Mac Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are no listeners. I cut them out in an attempt to minimize the program like it was suggested some posts above.
The question for the listeners was attempted to ask, wether a listener is obligatory. Maybe the non-existence of listeners causes problems?
 
Tony Docherty
Bartender
Posts: 3195
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will Ashton wrote:There are no listeners. I cut them out in an attempt to minimize the program like it was suggested some posts above.
The question for the listeners was attempted to ask, wether a listener is obligatory. Maybe the non-existence of listeners causes problems?

No, listeners are not obligatory.
Can you post an SSCCE
 
Campbell Ritchie
Sheriff
Posts: 53720
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So removing the Listeners does not sort out the problem?

As Tony says, please post an example.
 
Will Ashton
Greenhorn
Posts: 22
Java Mac Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, listeners seem to have nothing to do with it.
Sry for the late reply, I had no time for programming yesterday.

Here is the example:



I was a bit in a hurry, so I had no time for playing around with it, but it seems, that the problems are caused either by the Fullscreen or the setLayout (null) or the setBounds (int,int,int,int). I might do some experiments tomorrow or at the weekend.
It would be nice, if somebody could test this on a Windows/Linux computer, to see, wether its maybe is just a Macintosh problem?
 
Tony Docherty
Bartender
Posts: 3195
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all setting the layout manager to null means you have to manually set the location and size of the components, as you are not doing this nothing will show up.
Secondly, I think you need to set the full screen mode after the frame has been set to visible.

Thirdly, having set a layout manager and moved the full screen mode to the end of the constructor it works under windows 7 using Java 7.
 
Will Ashton
Greenhorn
Posts: 22
Java Mac Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all setting the layout manager to null means you have to manually set the location and size of the components, as you are not doing this nothing will show up.

In the real program I have a FlowLayout inside the tabbedpane tab. In the example Im using setBounds on all components.

Secondly, I think you need to set the full screen mode after the frame has been set to visible.


Seems to be a matter of preference. In other topics I have been criticised for placing it earlier in the constructor, because people said, it should be the last thing to do...

Thirdly, having set a layout manager and moved the full screen mode to the end of the constructor it works under windows 7 using Java 7.


Thanks for testing. I will have time for programming tomorrow.
The only problem with this is, that I use a superclass to build the Frame and the Fullscreen Mode. To do this, I requiere the super() statement, which needs to be the first statement in the constructor. Do you have any ideas on that? Or should I just leave the superclass out and contruct manually ( does not seem very OO to me)?
 
Tony Docherty
Bartender
Posts: 3195
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will Ashton wrote:
Secondly, I think you need to set the full screen mode after the frame has been set to visible.


Seems to be a matter of preference. In other topics I have been criticised for placing it earlier in the constructor, because people said, it should be the last thing to do...


Err, I think you have misunderstood, I'm saying you are placing it too early as well.

In what other topics have you had this advice - is this question cross posted on other forums?
 
Will Ashton
Greenhorn
Posts: 22
Java Mac Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I meant that the setVisible should be the last statement. I have been given this advice in another forum on a totally different question several months before.

Well, i just made the changes you suggested (placing Fullscreen-statements in the end and set a LayoutManager) on the Example-program, but this doesnt solve anything for me
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!