Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding items to JComboBox, taken from a JTextField's listener

 
Kaspersky Ukshini
Ranch Hand
Posts: 122
C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys, I need to take the value of what's typed in my JTextField, and once the submit button is clicked, I want to add that string to my JComboBox list items.


Depending which RadioButton they selected, I need to put the team in HOME or AWAY teams, and so on and so on, until they continue clicking submit.
Can you please give me an idea?

 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure. But you're going to have to tell us what idea you want. Do you not know how to do something when the Submit button is pressed? Or don't you know how to get information from the text field? Tell us your question.
 
Kaspersky Ukshini
Ranch Hand
Posts: 122
C++ Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Sure. But you're going to have to tell us what idea you want. Do you not know how to do something when the Submit button is pressed? Or don't you know how to get information from the text field? Tell us your question.


I curently have a listener for the "Dodadi Tim!" button, once that button is clicked I have to get the value from the textfield, check which jradiobutton is selected, then add the string to one of the comboboxes.. I also know how to add items to a JComboBox manualy, for example:

JComboBox doma=new JComboBox("Team1", "Team2","Team3");
but I don't know how to add more teams to my JComboBox, how do I do that?

EDITED: done! I used .addItem and it's working great!
THANK YOU!
 
Kaspersky Ukshini
Ranch Hand
Posts: 122
C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay guys, now I'm stuck here...


I need to add a try, catch, throw, or whatever they are called to this listener. if non of the teams, or tips are selected, I have nothing to display when they hover their mouse over a certain button, so I need to write something like "you havent selected anything".

How do I do that?
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally I don't like having buttons which give you error messages when you click them. So my preference would be to disable the button until it can do something useful. I think that would mean in your case, not until the user has selected a team or a tip. So you start with the button disabled, and when the controller sees the user select one of those things (via a SelectionListener I believe) it should enable the button.
 
Kaspersky Ukshini
Ranch Hand
Posts: 122
C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a school assigment mate, we have to do it that way, so they can check if we know how it's done. I tried putting the whole code in try{}, but I don't know what to type in catch() {}...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!