Re: Justifying box components
- From: Knute Johnson <nospam@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 06 Nov 2007 09:14:30 -0800
H.L wrote:
I want to put a JSlider underneath a label explaining what it is there
for. I have used a Box object instantiated with the createVerticalBox
constructor. The problem is that the text and the slider has a bad
alignment. Is there any way to make them both centered or justified to
either side of the column? Thanks in advance.
Håkan Lane
I haven't played with BoxLayout much but what you want to do is really easy with GridBagLayout.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class test {
public static void main(String[] args) {
Runnable r = new Runnable() {
public void run() {
JFrame f = new JFrame("test");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.gridy = 0; c.insets = new Insets(2,2,2,2);
c.anchor = GridBagConstraints.CENTER;
JLabel l = new JLabel("JSlider Info");
f.add(l,c);
++c.gridy;
JSlider s = new JSlider(0,100,50);
f.add(s,c);
f.setSize(400,300);
f.setVisible(true);
}
};
EventQueue.invokeLater(r);
}
}
--
Knute Johnson
email s/nospam/knute/
.
- References:
- Justifying box components
- From: H.L
- Justifying box components
- Prev by Date: Justifying box components
- Next by Date: JDesktop Web Component Crashing
- Previous by thread: Justifying box components
- Next by thread: Re: Justifying box components
- Index(es):
Relevant Pages
|