• Post Reply Bookmark Topic Watch Topic
  • New Topic

No word wrap in Flow Layout  RSS feed

 
Harsh Misra
Greenhorn
Posts: 5
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Used the mainPanel in Ch-13 of Head First Java with the default layout.
That I consider would be FlowLayout.
But I am not getting any checkBoxes on screen.
I think the word wrap is not working in FlowLayout.

Thanks for the help in advance.
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please show us your code.
 
Paul Clapham
Sheriff
Posts: 22509
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're asking two questions there, aren't you? Or are you suggesting that word-wrap is somehow connected to the display of check boxes? So yes, showing us your code would be helpful, but clarifying the post would help too.
 
Harsh Misra
Greenhorn
Posts: 5
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am really sorry for not posting the code.
The code runs this way.



The code compiles perfectly but I am not getting any checkBoxes on the Frame.
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please indent all caode before you post it; that block of code is incomprehensible without it. Also avoid long lines; because I broke the one long line (and you can see how to do it for future reference), the left‑and‑right scrolling has gone.

Where are you adding the check boxes to the display?
 
Knute Snortum
Sheriff
Posts: 4087
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question may get more traction in the Swing forum; moving.
 
Paul Clapham
Sheriff
Posts: 22509
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're creating a JPanel (referred to by "mainPanel") with check boxes in it, but I don't see where you add that JPanel to your GUI.
 
Rob Camick
Ranch Hand
Posts: 2801
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all the basic structure of your code should be something like:



That is:

1. when using the add(...) method you specify the component first and the constraint second. Not all layout manager need a constraint, so always add the component and then the constraint only when needed.
2. the default layout manager for the content pane of a JFrame is a BorderLayout, so you don't need to create your own panel to hold all your components if that panel is just using a BorderLayout
3, Since JDK4 there is no need to use the getContentPane() method to access the content pane. The JFrame will add component to the content pane for you.
4. Component should be added to the frame BEFORE packing the frame and making it visible.

Head First Java


If your code is based on that book then I suggest you get rid of the book.

Instead you should be using the example from the Swing tutorial. These examples are more up to date and show betters ways to structure your code, including using SwingUtilities.invokeLater(...) to make sure your GUI is created on the Event Dispatch Thread.



The above line is the problem with your code. A GridLayout wants to display components in a grid, but you need to tell the layout how big the grid should be. Try:

GridLayout grid = new GridLayout(0, 16);

This will create a new line for every 16 components.
 
Harsh Misra
Greenhorn
Posts: 5
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick--- Thanks mate...the correction in GridLayout function worked. And will look forward to Swing Tutorial for help. Thanks again

Paul Clapham --- I did add the mainPanel .
I didn't add it to the frame but to the "back" panel. Thanks for the concern.

Knute Snortum --- Will lok forward to it.Thanks

Campbell Ritchie --- I will try to be more specific for my further queries. Thanks for being patient .
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harsh Misra wrote:I did add the mainPanel .


Did you miss this?
Rob Camick wrote:1. when using the add(...) method you specify the component first and the constraint second.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!