Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Trouble updating JComboBox on JTabbedPane event click

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I've got another puzzle for you...

I've created a small swing application which has 2 tabs.
the contents of each tab is created in a seperate class returning a JPanel.

The 2nd tab is where the user can edit, delete, or create new files.
When either a new file is created or an existing one is deleted an array is updated containing
the names of remaining files.

The 1st Tab is where the user would be able to read files and compare files with other files.
So on the 1st Tab there is a JComboBox which contains the list of files.

In my frame class is where I implement the JTabbedPane for the two tabs.
Here is where I have the changeListener located.

Here's the code where I'm having the issue:
Seems every time I try this I get a NullPointerException where indicated below in the code.



I also tried to putting the body of code I have within the ChangeListener above into its own
method of the 1st Tab class and call it from the ChangeListener of the frame class and also
get a NullPointerException in the same place.

Let me know if if you have any ideas on this, I've scoured oracles site and countless others with no luck
and have worked on solving this on my own for two days now, feeling quite frustrated at this point.

Any help would be greatly appreciated.
 
Marshal
Posts: 25798
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, that would be because mp.select_cmb is null. What else could it be -- mp certainly can't be null at that point.

But I don't understand why you're creating a new MainPanel in that code. If I understand your design correctly, you already have a MainPanel displayed and you want to be working with that MainPanel.
 
Ranch Hand
Posts: 178
2
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you will get no error if you used your existing MainPanel. (I think you mentioned as my Panel to MainPanel)
 
Joe McTigue
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,

Thanks for checking this out.
There are four classes involved in this.
My entire application has 13 classes.
The code for the ChangeListener is located in the class I have my main method in.
The class MainPanel class is a seperate class that holds several methods which build the Panels for the first tab.
and The AddEditFormatter class is a seperate class that holds several methods which build the Panels for the second tab.

I hope that helps in understanding the local issue I presented.

I've verified that the JComboBox (select_cmb) located in the MainPanel class is not null.
But I still get a NullPointerException when I try to access it.

I've done this before without issue back in Java SE version 1.4, can't seem to figure out what's changed in verion 6
and what's replaced this usage. I've read over the documentation several times of what I could find, just haven't
found anything other than old documentation saying this method of doing this won't be supported after version 1.4.2.

There's got to be another way that exists to do the same thing.

Any help would be appreciated.

 
Joe McTigue
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got this one figured out. :-)

I changed my code to the following:


Then from my MainPanel class I created the updateComboboxSelections() method as follows:


I actually tried this same approach in my first attempt and failed.
It seems the only thing different was my making mp a class varible.

consider this issue solved.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic