Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-02-2007, 09:04 PM
Member
 
Join Date: Oct 2007
Posts: 11
toad is on a distinguished road
Help Using FlowLayout Manager
Code:
// Exercise12_2.java: Practice on containers and layout import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Exercise12_2 extends JFrame implements ActionListener { private JButton jbt1, jbt2, jbt3, jbt4, jbt5, jbt6; public static void main(String[] args) { Exercise12_2 frame = new Exercise12_2(); frame.pack(); frame.setTitle("Exercise12_2"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } public Exercise12_2() { // Create panel p1 add three buttons JPanel p1 = new JPanel(); p1.setLayout(new FlowLayout()); p1.add(jbt1 = new JButton("Button 1")); p1.add(jbt2 = new JButton("Button 2")); p1.add(jbt3 = new JButton("Button 3")); // Create Panel p2 and add three buttons JPanel p2 = new JPanel(); p2.setLayout(new FlowLayout()); p2.add(jbt4 = new JButton("Button 4")); p2.add(jbt5 = new JButton("Button 5")); p2.add(jbt6 = new JButton("Button 6")); // Place p1 and p2 in the frame getContentPane().setLayout(new BorderLayout()); getContentPane().add(p1, BorderLayout.SOUTH); getContentPane().add(p2, BorderLayout.CENTER); // Register listeners jbt1.addActionListener(this); jbt2.addActionListener(this); jbt3.addActionListener(this); jbt4.addActionListener(this); jbt5.addActionListener(this); jbt6.addActionListener(this); } public void actionPerformed(ActionEvent e) { System.out.println(e.getActionCommand() + " was clicked"); } }
I wrote the code above using the BorderLayout manager. I now need to revise the same code using the FlowLayout manager. There needs to be two panels with three buttons in each panel. Each panel uses FlowLayout.

The above code took me a while to get working properly. I assume it should be easy to revise but I'm not quite sure how to pull it off. Thanks in advance.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-03-2007, 02:16 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Code:
getContentPane().setLayout(new FlowLayout()); getContentPane().add(p1); getContentPane().add(p2);
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-03-2007, 02:43 AM
Member
 
Join Date: Oct 2007
Posts: 11
toad is on a distinguished road
I figured it was an easy conversion but did not realize it was that easy. Sometimes the obvious is the hardest to see.

Thanks.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
New Line in FlowLayout chris12295 New To Java 1 12-07-2007 07:49 PM
MeD's Movie Manager 2.5.4.1 levent Java Announcements 0 07-26-2007 10:29 PM
Ricebridge CSV Manager 1.2.4 JavaBean Java Announcements 0 06-22-2007 02:49 AM
Ricebridge CSV Manager 1.2.3 levent Java Announcements 0 06-07-2007 10:51 AM
MiG Layout Manager 2.4 levent Java Announcements 0 05-16-2007 07:11 AM


All times are GMT +3. The time now is 04:34 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org