• Post Reply Bookmark Topic Watch Topic
  • New Topic

ComboBox If/Else -> New Labels and TextFields

 
Jens Schulz
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I'am a beginner and working on a project at school, but I got stuck and i dont know really what i do wrong.

Problem:

I want to use the ComboBox in which i store two values of the typ string.

If value 1 is selected i want a certain amount of labels and textfields appear and if value 2 is selected the same but different. I use the following code:



I did delete the unnecessary parts. So if i run my programm, he always executes the else if part immediately, without me chosing anything and even if i chose the Typ 1 value, its the same outcome. So where do i make the mistake?



 
Campbell Ritchie
Marshal
Posts: 52549
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You are testing whether the typBox (the combo box) is equal to the String value. That is always going to return false.
It is a long time since I used a combo box, but I think you are supposed to get the selected value. You can read all about it in the Java™ Tutorials, and it will doubtless tell you how to find out which value is selected.

Remember you can use Strings after the case keyword in a switch statement.
 
Rob Camick
Ranch Hand
Posts: 2699
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
working on a project at school,


Well, I would fail you.

Variable names should NOT start with an upper case character.

However class names SHOULD start with an upper case character.

Follow examples from your text book and tutorials on the web and don't make up your own conventions.
 
Jens Schulz
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:
working on a project at school,


Well, I would fail you.

Variable names should NOT start with an upper case character.

However class names SHOULD start with an upper case character.

Follow examples from your text book and tutorials on the web and don't make up your own conventions.


Good thing you're not my teacher then.

We do not have text books, just a very simple list of commands and explanation and i havent found a tutorial yet in which is explained how to use swing components to alter the design of a swing based frame. I know its possible and i have a gerneral idea, but ...
 
Rob Camick
Ranch Hand
Posts: 2699
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i havent found a tutorial yet


You were given a link to the Swing tutorial in the first response. It contains many working examples. 

The examples follow Java conventions and give some simple direction on structuring your code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!