Results 1 to 10 of 10
Thread: GridLayout alignment problem
- 03-15-2010, 07:47 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 5
- Rep Power
- 0
GridLayout alignment problem
hello everyone,
i`m new in java and it is the first homework,
everything was done, unless the position of the graph.
i use GridLayout N*N and as i said it work fine but there no space between the edges and first column, so how to add this space..?
and how to make the last column have the same size between edges and and first column..?
i hope somebody have solution of my above problem, because i was search in google for built in function that add space before first column and i fail.
-
GridLayout allows you to specify horizontal and/or vertical gaps in the grid. Check out the GridLayout section of the API and it will show you how to do this using GridLayout's constructor.
- 03-15-2010, 09:22 PM #3
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,236
- Rep Power
- 10
Add a Border to the main panel?
- 03-15-2010, 11:03 PM #4
Member
- Join Date
- Mar 2010
- Posts
- 5
- Rep Power
- 0
but when i add horizontal and vertical gap, first column is steel start from edges.
how to add border in main panel..?
can you give an example, plz..
--------------
Java Code:import java.applet.*; import java.awt.*; public class hw01 extends Applet{ GridLayout tt = (new GridLayout(3, 3, 100, 0)); public void init(){ setLayout(tt); add(new comp()); add(new comp()); add(new comp()); add(new comp()); add(new comp()); add(new comp()); add(new comp()); add(new comp()); add(new comp()); } } class comp extends Applet{ public void paint(Graphics g){ setSize(this.getHeight(), this.getHeight()); int h = getSize().height-10, w = getSize().width-10, x = 0, y = 0; g.drawRect(0, 0, w, h); for(int i = 0; i <= 10; i++){ g.drawLine(0, h, w, y); g.drawLine(0, h, x, 0); g.drawLine(w, 0, 0, y); g.drawLine(w, 0, x, h); x += w/10; y += h/10; } } }
- 03-16-2010, 02:24 AM #5
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,236
- Rep Power
- 10
Border is a Swing concept, so I guess it won't help.
I have no idea why schools still teach AWT. Everybody programs in Swing these days and that means you need to unlearn AWT concepts once you move on to Swing.
- 03-16-2010, 06:20 AM #6
Member
- Join Date
- Mar 2010
- Posts
- 5
- Rep Power
- 0
- 03-16-2010, 07:11 AM #7
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,571
- Rep Power
- 12
Add Insets to the "outer" cells, or, as a small (unnecessary) trick, add a column and/or row to the sides and/or top/bottom with nothing but a simple label in it consisting of a single space (i.e. one label in the top left and one label in the bottom right).
- 03-16-2010, 07:04 PM #8
Member
- Join Date
- Mar 2010
- Posts
- 5
- Rep Power
- 0
- 03-16-2010, 07:48 PM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,421
- Blog Entries
- 7
- Rep Power
- 26
Put your JPanel with the GridLayout in another JPanel with a BorderLayout (in the center) and put two invisible Boxes (read the API documentation) in the EAST and WEST parts. Note that nesting JPanels in JPanels with different LayoutManagers can do quite a powerful job.
kind regards,
Jos
- 03-16-2010, 07:54 PM #10
Member
- Join Date
- Mar 2010
- Posts
- 5
- Rep Power
- 0
that what i try to do now, but there are no output..!!
what i do is add this code to the above code in my previous code
Java Code:public class hw01 extends Applet{ public void init(){ setLayout (new BorderLayout()); add(new comp2(), BorderLayout.CENTER); } }
is it true or should i do it in another way..?
Similar Threads
-
SWT GridLayout Demo
By Java Tip in forum SWT TipsReplies: 0Last Post: 07-11-2008, 04:48 PM -
[SOLVED] alignment problem
By nanimtech in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 04-10-2008, 01:23 PM -
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 -
Gridlayout
By Marty in forum AWT / SwingReplies: 2Last Post: 05-31-2007, 11:48 AM
Bookmarks