aspose file tools*
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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Need component separator ->" Watch "Need component separator ->" New topic
Author

Need component separator ->

Dominic Steng�rd
Ranch Hand

Joined: Feb 05, 2001
Posts: 186
Hello!
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?
Regards
------------------
Dominic Steng�rd
Sun Certified Java 2 Programmer
------------------


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

Joined: Jan 24, 2001
Posts: 18
Dear,
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");
testArea.add(button1,BorderLayout.NORTH);
JButton button2 = new JButton("Button2");
testArea.add(button2,BorderLayout.WEST);
JButton button3 = new JButton("Button3");
testArea.add(button3,BorderLayout.CENTER);
c.add(testArea);
setSize(300,200);
show();
}//end constructor
public static void main(String[] args) {
TestDraw app = new TestDraw();
app.addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
);
}//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 further.do get back in case u have any problem
regards
deeksha
Grant Crofton
Ranch Hand

Joined: Nov 08, 2000
Posts: 154
Label separator = new Label( " " );
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need component separator ->