Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Variable number of answers in a question panel

 
Joe McTigue
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having the same question...
Is there anyway to print multiple lines into an AWT Label?
(I can not use a JLabel for what I'm trying to do.)
Any help or links offered would be appreciated.
 
Darryl Burke
Bartender
Posts: 5132
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe McTigue wrote:(I can not use a JLabel for what I'm trying to do.)


Would you care to elaborate why not?
 
Joe McTigue
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
elaborating...

I'm creating a test which displays an answer selection area (JPanel) which would have a series of possible answers categorized by letter.
each question would have as many as 15 possible answers to select from, or as little as three answers to select from.
I choose awt Checkbox's because JCheckBox's can not be removed or added to the JPanel at runtime.

example: (keep in mind the "|_|" are my checkboxes)

Question: 1
what is your favorite color?

Select the correct answer:
|_| A.) I like the color Blue best because it is the color of the // I'll need some to be multi-line checkboxes.
sky and water, my favorite two things on the planet.

|_| B.) I like the color Green best because it is the color of lush
forrest and jungles and I really like to explore.

Question: 2
what is your least favorite color?

Select the correct answer:
|_| A.) Blue

|_| B.) Green

|_| C.) Yellow // I don't want checkbox 'C' to show up in the selections for Question 3.

Question: 3
Which of the previous two questions did you like most?

|_| A.) the first one

|_| B.) the second one.

 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe McTigue wrote:I choose awt Checkbox's because JCheckBox's can not be removed or added to the JPanel at runtime.

I'm pretty sure that's not true. If you do it correctly you can add and remove any Swing components dynamically.
 
Darryl Burke
Bartender
Posts: 5132
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
++ to what Matthew said. Additionally, the appropriate Swing UI for selecting one of many options would be a bunch of JRadioButtons added to a ButtonGroup -- not JCheckBoxes at all.

edit: and as this has nothing at all to do with the subject of the thread you posted in, which is "multi line in a java.awt.Label" I'm splitting this discussion into a new thread.
 
Joe McTigue
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Matthew Brown:
If this can be done with JCheckBoxes, please tell me how one can dynamically remove a
JCheckBox from a JPanel and how to add a JCheckBox onto a JPanel during runtime.

@Darryl Burke:
Each question can have multiple answers.

Thanks in advance for any informative answers you can provide in advance.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> how one can dynamically remove a JCheckBox from a JPanel and how to add a JCheckBox onto a JPanel during runtime.

here's a demo for add, remove is very similar

run, then click the button one or more times
 
Joe McTigue
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Michael Dunn:
Very Cool, thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic