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 07-24-2007, 05:24 PM
Member
 
Join Date: Jul 2007
Posts: 40
toby is on a distinguished road
Use GridLayout in java
Hi, I am trying to make a Java Applet and using gridlayout
Here's the code:

Code:
setLayout(new GridLayout(2,2)); ButtonA = new Button("A"); ButtonB = new Button("B"); ButtonC = new Button("C"); ButtonD = new Button("D"); add(ButtonA,"1"); add(ButtonB,"2"); add(ButtonC,"3"); add(ButtonD,"4");
Unfortunately, this code makes all the buttons stretch towards the whole screen that's 400x400, what if i want to make it in the middle that's 200x200 on a 400x400 applet.
Thanks
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-04-2007, 02:44 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Code:
// <applet code="GridLayoutTest" width="400" height="400"></applet> import java.applet.Applet; import java.awt.*; public class GridLayoutTest extends Applet { public void init() { Panel center = new Panel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); center.add(new ButtonPanel(), gbc); setLayout(new BorderLayout()); add(center); } private class ButtonPanel extends Panel { public ButtonPanel() { Button ButtonA = new Button("A"); Button ButtonB = new Button("B"); Button ButtonC = new Button("C"); Button ButtonD = new Button("D"); setLayout(new GridLayout(2,2)); add(ButtonA,"1"); add(ButtonB,"2"); add(ButtonC,"3"); add(ButtonD,"4"); } public Dimension getPreferredSize() { return new Dimension(200,200); } } }
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
SWT GridLayout Java Tip Java Tips 0 01-08-2008 11:04 AM
GridLayout with animation? tojas AWT / Swing 3 11-13-2007 12:16 AM
Help with gaps in GridLayout trill AWT / Swing 1 07-31-2007 09:20 PM
Gridlayout Marty AWT / Swing 2 05-31-2007 01:48 PM


All times are GMT +3. The time now is 07:56 AM.


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