Re: Layout question
On Jan 30, 9:54 pm, nukl...@invalid.addr (nukleus) wrote:
In article <1170129146.373308.103...@a75g2000cwd.googlegroups.com>,
....
I wonder if you might give me a hint on how would
you layout that frame I described in my previous post.
I might (at least, as well as I understand your description)..
<sscce>
import javax.swing.*;
import java.awt.*;
class ExampleNestedLayout extends JPanel {
ExampleNestedLayout() {
super( new BorderLayout(5,5) );
JToolBar tb = new JToolBar();
// extra measures need to be taken,
// to ensure toolbars can 'float'
// correctly, we keep it simple.
tb.setFloatable(false);
for (int ii=1; ii<5; ii++) {
tb.add( new JButton("Button " + ii ) );
}
add( tb, BorderLayout.NORTH );
JPanel textFieldContainer =
new JPanel(new GridLayout(0,1,5,5));
for (int ii=1; ii<5; ii++) {
textFieldContainer.add( new JTextField() );
}
JPanel textEditContainer = new JPanel(
new BorderLayout(5,5) );
textEditContainer.add(
textFieldContainer, BorderLayout.NORTH );
textEditContainer.add(
new JScrollPane( new JTextArea(5,20) ) );
add( textEditContainer, BorderLayout.WEST );
JPanel checkBoxContainer = new JPanel(
new FlowLayout( FlowLayout.CENTER, 5, 5 ) );
for (int ii=1; ii<15; ii++) {
checkBoxContainer.add(
new JCheckBox("CheckBox " + ii) );
}
add( checkBoxContainer, BorderLayout.CENTER );
}
public static void main(String[] args) {
JFrame f = new JFrame("Example Nested Layout");
f.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(
new ExampleNestedLayout() );
f.pack();
f.setMinimumSize( new Dimension(450,300) );
f.setSize( 800,400 );
f.setLocationRelativeTo(null);
f.setVisible(true);
}
}
</sscce>
HTH
Andrew T.