• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Getting String text from a "private" combobox

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I´m having a problem with my coding, what I want to do is to get the loop to update a String with the information of a combobox which is private (I´m using NetBeans and I can´t get it to make the combobox public). Here´s my Main:



And here´s the code for the combobox:


I Hope you understand what I mean. Thanks in advance, any help is very apreciated.

[edit]Insert newlines in the code CR[/edit]
 
Marshal
Posts: 80754
486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch
Thank you for finding the code button.

I think what you are doing is writing Panelet which is the name of the class, rather than panel which is the identifier for the instance.
But you are setting up the Panelet object in the main method, so it is out of scope when you reach the Main class.

Not certain about the rest of it, but . . .
I suspect you need to move all the code to set up the GUI into the Main class (probably the constructor), and move the code to start the Thread into the main method.

If the JComboBox has private access in the Panelet class, you should provide getter methods which provide access to the selected item in the JComboBox.

Rather than struggling with NetBeans (although it is correct to insist on private access to a field) you should consider a decent text editor (if on Windows try jEdit. NotePad2 or NotePad++, not NotePad) and using the command line.
 
Esben Christensen
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your quick answer but it´s for an exam project and we have to make it through NetBeans, can you clarify how you would do that getter methods to provide access to the selected item in the JComboBox?

Thanks in advance
 
Campbell Ritchie
Marshal
Posts: 80754
486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The usual way. Set up a getSelectedComboboxItemAsString() method which returns the myCombobBox.getSelectedItem().etc().

If it is for an exam, I oughtn't to say any more, or it could lose you marks.
 
Esben Christensen
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I´ve made it work as long as I´m not using the loop but I need it to do it every time the loop runs through that´s my major problem, as for the exam part we are allowed to get help for our projects as long as we are open about it.

Any idea how to make it work in a loop? I´ve tried so many things but can´t make it work.

Thanks in advance
 
Campbell Ritchie
Marshal
Posts: 80754
486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What have you tried? Where did you put the loop?
 
Esben Christensen
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've tried with this in the Panelet class which contains my GUI:


In my Main loop


Mainly things like that moving the sentences around but never getting it to do it.




 
Campbell Ritchie
Marshal
Posts: 80754
486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think either of those solutions will work.

Back to square 1. How are you going to get the details of the selected Object from the combo box? To help: API documentation. Then how are you going to return that information from the Panelet class?

Remember: fields ought to have private access, so you shouldn't use a . before the name of the field outside its own class.
 
Esben Christensen
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for trying to help but I really can´t figure out how to get the SelectedItem out of the JComboBox and into a String in a loop. without the loop I made it work with the following in the class Panelet:


but again I really need it to work through the loop.
 
Campbell Ritchie
Marshal
Posts: 80754
486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where does the ComboBoxActionPerformed method come from? Is it something NetBeans has added for itself? It doesn't appear to be part of the standard Sun API.
Is ComboBox a class or an object? It is confusing if you don't follow the usual capitalisation conventions.
 
Esben Christensen
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The ComboBoxActionPerformed method comes from NetBeans indeed and by ComboBox i Mean the ComboBoxActionPerformed. Sorry for the confusion
 
Campbell Ritchie
Marshal
Posts: 80754
486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Still can't understand how the ComboBoxActionPerformed method is called, but it appears to work. . . . What have you done about loops?
 
reply
    Bookmark Topic Watch Topic
  • New Topic