• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Variable number of answers in a question panel

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Michael Dunn:
Very Cool, thanks!
reply
    Bookmark Topic Watch Topic
  • New Topic