Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need component separator ->

 
Dominic Steng�rd
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
------------------
 
Anh Nguyen
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Dominic Steng�rd
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Label separator = new Label( " " );
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic