Meaningless Drivel is fun!
The moose likes Swing / AWT / SWT and the fly likes Need component separator -> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Need component separator ->" Watch "Need component separator ->" New topic

Need component separator ->

Dominic Steng�rd
Ranch Hand

Joined: Feb 05, 2001
Posts: 186
I have an JPanel which contains several components (JButtons, JTextAraes etc) and every now and then I need to use a separator to get some space between the components. Up to now I have used an invisible Canvas for this purpose, but it gives me some "not so nice" problems, so I would like to know if there is any other Swing component which is good for this purpose?
Dominic Steng�rd
Sun Certified Java 2 Programmer

Dominic Steng�rd<br />Sun Certified Java 2 Programmer
Anh Nguyen

Joined: Jan 24, 2001
Posts: 18
Most of the Layout Manager let you specify the vgap and the hgap between the components which it contains . BorderLayout and GridLayout are the some of them .
Ex :
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TestGap extends JFrame{
public TestGap(){
super("Test hgap and vgap using BorderLayout");
Container c = getContentPane();
JPanel testArea = new JPanel();
testArea.setLayout(new BorderLayout(5,10));//use BorderLayout with 5 pixels horizontal gap and 10 pixels verticle gap between components in it
JButton button1 = new JButton("Button1");
JButton button2 = new JButton("Button2");
JButton button3 = new JButton("Button3");
}//end constructor
public static void main(String[] args) {
TestDraw app = new TestDraw();
new WindowAdapter(){
public void windowClosing(WindowEvent e){
}//end main
}//end program

... No one can escape .......<BR><B>Heavenly Evil Knight</B>
Dominic Steng�rd
Ranch Hand

Joined: Feb 05, 2001
Posts: 186
Hello Anh!
Thanks for your reply!
Yes, I know about the vgap hgap, but these will put a gap between all components and I only want a gap between some of the components. So, still I need to find a separator which is better than a canvas.
deekasha gunwant
Ranch Hand

Joined: May 06, 2000
Posts: 396
Hi Dominic,
Swing provides BoxLayout/Box class in which we can create glues/struts/rigid areas etc. to play with the space between components.
i hope u can explore the things get back in case u have any problem
Grant Crofton
Ranch Hand

Joined: Nov 08, 2000
Posts: 154
Label separator = new Label( " " );
I agree. Here's the link:
subject: Need component separator ->
It's not a secret anymore!