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

FlowLayout issue

 
Geoff Vurel
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am looking for some assistance with two questions.
1. How do I make the 'About' button show in the 'bowling prices' window and then 'launch in another frame' frame open when clicking 'About' from the 'Bowling Prices' window.
2. FlowLayout isn't showing all my fields as I need it to. The "Bowler Type" field has data that is not showing.

I don't have to use flowlayout, if another layout would work better please advise.

 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does your current code compile?

In particular, do these lines compile?



Also, you seem to be trying to add the same components to a JPanel and to the contentPane both at the same time. Why?

You shouldn't have a FlowLayout() statement when adding a component as you've done above, and also, it almost appears as if you are trying to call the FlowLayout constructor without new which is never done in Java much less in Swing.

I strongly advise you to read the layout manager section of the Swing tutorials with attention to the FlowLayout, the BorderLayout, and the GridLayout. Later I'd add the BoxLayout, and much later the GridBagLayout. After reading this section, consider using nested JPanels to hold your components with each JPanel using its own layout manager. For instance you could let the contentPane use its default BorderLayout, then have a top panel that holds your jlabel, your jtextfield (though a jspinner that uses a spinnernumbermodel may work better here), and your jcheckbox. This could be placed in the contentPane BorderLayout.NORTH. Then add your jtextarea to a jscrollpane and add it BorderLayout.CENTER, and finally place whatever buttons you need, including the about button in its own JPanel that uses the default FlowLayout or GridLayout, and place it in the contentPane BorderLayout.SOUTH. Good luck, and YMMV.

Pete
 
Campbell Ritchie
Sheriff
Pie
Posts: 49442
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pete Stein is right. It might be worthwhile looking for MigLayout too (Google). Also find the Java Tutorials on the Sun website, and there is a section about different layouts.
 
Geoff Vurel
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My code does not compile, sorry I thought I included the errors. We have not covered MigLayout in my class. I have to use BorderLayout, FlowLayout, or Boxlayout in this project. Here are the errors I get when compiling right now.

Project01b.java:33: cannot find symbol
symbol : method FlowLayout()
location: class Project01b
panel.add(choice, FlowLayout());
^
Project01b.java:35: cannot find symbol
symbol : method FlowLayout()
location: class Project01b
panel.add(choice, FlowLayout());
^
Project01b.java:38: cannot find symbol
symbol : method FlowLayout()
location: class Project01b
panel.add(choice, FlowLayout());
^
3 errors
 
Suraj Chandran
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are using it the wrong way,. Try something like this:
panel.setLayout(new FlowLayout());
panel.add(choice);

OR

panel.setLayout(new BorderLayout());
panel.add(choice, BorderLayout.SOUTH);
 
Campbell Ritchie
Sheriff
Pie
Posts: 49442
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suraj Chandran has given you the answer. You won't cover MigLayout in lectures; it is not a standard Java class, but its designers are trying to get it incorporated into Java. A lot of people say it is easier to use than GridBag or GroupLayout, but I have never tried it myself.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic