This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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 ->
 
Similar Threads
focus selection of components
placing swing components
Display contents in GUI format
How to use user Defined separator in JPopupMenu instead of addSeparator() provided by Java Swing
Authorization in JSF based on permission of a component