• 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

FlowLayout issue

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
incandescent light gives off an efficient form of heat. You must be THIS smart to ride this ride. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic