This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Variable number of answers in a question panel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Variable number of answers in a question panel" Watch "Variable number of answers in a question panel" New topic
Author

Variable number of answers in a question panel

Joe McTigue
Ranch Hand

Joined: Mar 05, 2012
Posts: 52
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

Joined: May 03, 2008
Posts: 4522
    
    5

Joe McTigue wrote:(I can not use a JLabel for what I'm trying to do.)


Would you care to elaborate why not?


luck, db
There are no new questions, but there may be new answers.
Joe McTigue
Ranch Hand

Joined: Mar 05, 2012
Posts: 52
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

Joined: Apr 06, 2010
Posts: 4240
    
    7

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

Joined: May 03, 2008
Posts: 4522
    
    5

++ 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

Joined: Mar 05, 2012
Posts: 52
@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

Joined: Jun 09, 2003
Posts: 4632
> 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

Joined: Mar 05, 2012
Posts: 52
@Michael Dunn:
Very Cool, thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Variable number of answers in a question panel
 
Similar Threads
What is the maximum score?
Are there some industry standards for software security?
Link and Actual Page are seems to be different
personality test
any Moderator that not Certified?