Results 1 to 2 of 2
Thread: Use GridLayout in java
- 07-24-2007, 03:24 PM #1
Member
- Join Date
- Jul 2007
- Posts
- 40
- Rep Power
- 0
Use GridLayout in java
Hi, I am trying to make a Java Applet and using gridlayout
Here's the code:
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.Java 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");
Thanks
- 08-04-2007, 12:44 AM #2
Java 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); } } }
Similar Threads
-
SWT GridLayout
By Java Tip in forum Java TipReplies: 0Last Post: 01-08-2008, 09:04 AM -
GridLayout with animation?
By tojas in forum AWT / SwingReplies: 3Last Post: 11-12-2007, 10:16 PM -
Help with gaps in GridLayout
By trill in forum AWT / SwingReplies: 1Last Post: 07-31-2007, 07:20 PM -
Gridlayout
By Marty in forum AWT / SwingReplies: 2Last Post: 05-31-2007, 11:48 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks