Java Forum / GUI / June 2006
Layout problem driving me insane - panels, resizing, etc
jackp@spambob.com - 13 Jun 2006 18:35 GMT OK, so I'd like to think I understand enough about all the different layout managers (and have gotten each of them to work, on its own), but trying to actually get them to do what I want for my "real" application is proving to be an exercise in frustration.
I think there are a couple of very basic things I don't understand about layouts, but I can't for the life of me figure out what they are... so I hope you can teach a man to fish, as well as give a man a fish, like the supposedly chinese proverb goes.
My plan is to have an app consisting of a JTable, a row of JButtons under it, and a JTextArea under that. The table and text area should be as wide as the window. Now, as for the height, the row of buttons takes a certain amount, but the table and text area should somehow share whatever height is available (that's why I thought I should use GridBagLayout - now I'm not so sure any more).
Ideally, I'd like to specify a row number for the text area, so that anything more makes a scrollbar appear, but not a number of columns, so that the area uses all the available width.
I've stripped all of the app-specific stuff from the code, so that under a hundred lines remain. The resulting code doesn't display the buttons at all, there is unclaimed space at the bottom of the app (and between the components?), the text area is only as wide as the text it is initially displays, and most puzzling: the table doesn't display initially, but only when the window is resized beyond a certain width.
I'm that close to using absolute positioning, calculating the sizes manually whenever the window's resized, but what's the right way? Feel free to point out my stupid mistakes, and/or suggest sweeping changes, As long as the app behaves the way it should (or close to it) that's really enough for me.
Without further ado, here's the offending code:
import java.awt.*; import javax.swing.*; import javax.swing.table.*;
public class LayoutProblem extends JFrame {
public static void main(String[] args) { new LayoutProblem(); }
String columnNames[] = { "Column 1", "Column 2", "Column 3" }; String dataValues[][] = { { "0aa","bbb","ccc"}, { "0dd","eee","fff"}, { "0gg","hhh","iii"}, { "1aa","bbb","ccc"}, { "1dd","eee","fff"}, { "1gg","hhh","iii"}, { "2aa","bbb","ccc"}, { "2dd","eee","fff"}, { "2gg","hhh","iii"}, { "3aa","bbb","ccc"}, { "3dd","eee","fff"}, { "3gg","hhh","iii"}, { "4aa","bbb","ccc"}, { "4dd","eee","fff"}, { "4gg","hhh","iii"}, { "5aa","bbb","ccc"}, { "5dd","eee","fff"}, { "5gg","hhh","iii"}, { "6aa","bbb","ccc"}, { "6dd","eee","fff"}, { "6gg","hhh","iii"}, { "7aa","bbb","ccc"}, { "7dd","eee","fff"}, { "7gg","hhh","iii"}, { "8aa","bbb","ccc"}, { "8dd","eee","fff"}, { "8gg","hhh","iii"}, { "9aa","bbb","ccc"}, { "9dd","eee","fff"}, { "9gg","hhh","iii"}, { "aaa","bbb","ccc"}, { "ddd","eee","fff"}, { "ggg","hhh","iii"}, };
public LayoutProblem() {
JTable table; JButton button1, button2, button3, button4; JTextArea logArea;
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container cont = getContentPane();
cont.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints();
table = new JTable(dataValues, columnNames); JScrollPane scrollPane = new JScrollPane(table); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
c.gridx = 0; c.gridy = 0; c.gridwidth = 1; c.gridheight= 1; c.weightx = 1.0; c.weighty=1.0; c.anchor = GridBagConstraints.CENTER; cont.add(scrollPane, c);
JPanel buttonPanel = new JPanel(); buttonPanel.setBorder( BorderFactory.createRaisedBevelBorder() );
SpringLayout buttonPanelLayout = new SpringLayout(); buttonPanel.setLayout(buttonPanelLayout);
final int PADDING = 6;
button1 = new JButton("Button 1"); buttonPanelLayout.putConstraint(SpringLayout.WEST, button1, PADDING, SpringLayout.WEST, buttonPanel); buttonPanelLayout.putConstraint(SpringLayout.NORTH, button1, PADDING, SpringLayout.NORTH, buttonPanel); buttonPanel.add(button1);
button2 = new JButton("Button 2"); buttonPanelLayout.putConstraint(SpringLayout.WEST, button2, PADDING, SpringLayout.EAST, button1); buttonPanelLayout.putConstraint(SpringLayout.NORTH, button2, PADDING, SpringLayout.NORTH, buttonPanel); buttonPanel.add(button2);
button3 = new JButton("Button 3"); buttonPanelLayout.putConstraint(SpringLayout.WEST, button3, PADDING, SpringLayout.EAST, button2); buttonPanelLayout.putConstraint(SpringLayout.NORTH, button3, PADDING, SpringLayout.NORTH, buttonPanel); buttonPanel.add(button3);
button4 = new JButton("Button 4"); buttonPanelLayout.putConstraint(SpringLayout.WEST, button4, PADDING, SpringLayout.EAST, button3); buttonPanelLayout.putConstraint(SpringLayout.NORTH, button4, PADDING, SpringLayout.NORTH, buttonPanel); buttonPanel.add(button4);
buttonPanel.validate(); // is this needed? does it do anything?
c.gridx = 0; c.gridy = 1; c.gridwidth = 1; c.gridheight= 1; c.weightx = 1.0; c.weighty=0.0; c.anchor = GridBagConstraints.NORTHWEST; cont.add(buttonPanel, c);
logArea = new JTextArea(); c.gridx = 0; c.gridy = 2; c.gridwidth = 1; c.gridheight= 1; c.weightx = 1.0; c.weighty=1.0; c.anchor = GridBagConstraints.NORTHWEST; logArea.setText("---------------------------\n---------------------------\n---------------------------\n"); cont.add(logArea, c);
pack(); setSize(450,600); // initial app size setVisible(true);
}
}
// thanks for making it this far.
Vova Reznik - 13 Jun 2006 19:03 GMT It should be Container with BorderLayout that contains
JScrollPane with JTable as NORTH JPanel (FlowLayout or GridLayout or even BoxLayout) with JButton(s) as CENTER JTextArea as SOUTH
something like:
JTable tbl = new JTable(5, 8); JScrollPane scroll = new JScrollPane(tbl);
// 3 to compensate gap between JTable and JTableHeader and Border int h = tbl.getPreferredSize().height + 3 + tbl.getTableHeader().getPreferredSize().height; // --- default preferred size for JScrollPane is about 400x400 scroll.setPreferredSize(new Dimension(scroll.getPreferredSize().width, h));
JFrame f = new JFrame(); int btnNum = 6; JPanel btnPanel = new JPanel(new GridLayout(1, btnNum)); for (int i = 0; i < btnNum; i++) { btnPanel.add(new JButton("Button " + (i + 1))); } JTextArea txtArea = new JTextArea(5, 0); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(scroll, BorderLayout.NORTH); f.getContentPane().add(btnPanel, BorderLayout.CENTER); f.getContentPane().add(txtArea, BorderLayout.SOUTH); f.pack(); f.setVisible(true);
> OK, so I'd like to think I understand enough about all the different > layout managers (and have gotten each of them to work, on its own), but [quoted text clipped - 137 lines] > > // thanks for making it this far. Oliver Wong - 13 Jun 2006 19:06 GMT > My plan is to have an app consisting of a JTable, a row of JButtons > under it, and a JTextArea under that. The table and text area should be [quoted text clipped - 21 lines] > > Without further ado, here's the offending code: [snip]
It's been a while since I did Swing coding (been doing mostly SWT these days). Here's what I got. It does most of what you want, except the JTextArea doesn't fill the width, and I can't remember how to do that. Perhaps someone else can chime in.
<SSCCE>
import java.awt.GridBagConstraints; import java.awt.GridBagLayout;
import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextArea; import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities;
public class LayoutProblem extends JFrame {
public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { new LayoutProblem(); } }); }
String columnNames[] = { "Column 1", "Column 2", "Column 3" };
String dataValues[][] = { { "0aa", "bbb", "ccc" }, { "0dd", "eee", "fff" }, { "0gg", "hhh", "iii" }, { "1aa", "bbb", "ccc" }, { "1dd", "eee", "fff" }, { "1gg", "hhh", "iii" }, { "2aa", "bbb", "ccc" }, { "2dd", "eee", "fff" }, { "2gg", "hhh", "iii" }, { "3aa", "bbb", "ccc" }, { "3dd", "eee", "fff" }, { "3gg", "hhh", "iii" }, { "4aa", "bbb", "ccc" }, { "4dd", "eee", "fff" }, { "4gg", "hhh", "iii" }, { "5aa", "bbb", "ccc" }, { "5dd", "eee", "fff" }, { "5gg", "hhh", "iii" }, { "6aa", "bbb", "ccc" }, { "6dd", "eee", "fff" }, { "6gg", "hhh", "iii" }, { "7aa", "bbb", "ccc" }, { "7dd", "eee", "fff" }, { "7gg", "hhh", "iii" }, { "8aa", "bbb", "ccc" }, { "8dd", "eee", "fff" }, { "8gg", "hhh", "iii" }, { "9aa", "bbb", "ccc" }, { "9dd", "eee", "fff" }, { "9gg", "hhh", "iii" }, { "aaa", "bbb", "ccc" }, { "ddd", "eee", "fff" }, { "ggg", "hhh", "iii" }, };
public LayoutProblem() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); buildGUI(); pack(); setVisible(true); }
private void buildGUI() { this.setLayout(new GridBagLayout()); { JTable table = new JTable(dataValues, columnNames); JScrollPane scrollPane = new JScrollPane(table); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.gridwidth = 1; c.gridheight = 1; c.weightx = 1.0; c.weighty = 1.0; c.anchor = GridBagConstraints.CENTER; this.add(scrollPane, c); } { GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 1; c.gridwidth = 1; c.gridheight = 1; c.weightx = 1.0; c.weighty = 0.0; c.anchor = GridBagConstraints.CENTER; this.add(buildButtonPanel(), c); } { JTextArea logArea = new JTextArea(); logArea .setText("---------------------------\n---------------------------\n---------------------------\n"); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 2; c.gridwidth = 1; c.gridheight = 1; c.weightx = 1.0; c.weighty = 1.0; c.anchor = GridBagConstraints.CENTER; this.add(new JScrollPane(logArea), c); } }
private JPanel buildButtonPanel() { JPanel buttonPanel = new JPanel(); buttonPanel.setBorder(BorderFactory.createRaisedBevelBorder()); BoxLayout buttonPanelLayout = new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS); buttonPanel.setLayout(buttonPanelLayout); JButton button1, button2, button3, button4; button1 = new JButton("Button 1"); buttonPanel.add(button1); button2 = new JButton("Button 2"); buttonPanel.add(button2); button3 = new JButton("Button 3"); buttonPanel.add(button3); button4 = new JButton("Button 4"); buttonPanel.add(button4); return buttonPanel; }
} </SSCCE>
- Oliver
Mark Space - 13 Jun 2006 19:27 GMT > OK, so I'd like to think I understand enough about all the different > layout managers (and have gotten each of them to work, on its own), but At risk of being a target for thrown keyboards and mice, why not just get NetBeans and use Matisse to layout your Swing components?
jackp@spambob.com - 13 Jun 2006 20:13 GMT (replying to my own post, because it's a little better than replying separately to all 3)
First, thank you all very much.
Vova: Wow, I've been struggling with the old (grid) bag all this time... it looks like switching to a simpler manager actually solves most of the problems. I also put a scrollPane around the textArea - now the only problem is that when the window's resized, it's the button panel that benefits/suffers from it, instead of the table and text area!
I didn't use your setPreferredSize because it seemed to make the situation worse (I really don't like how... unscientific... this process seems to me).
I'd still like to know what's wrong with the original code though..
Oh, and the buttons were not in a loop because in the original code they actually have different names and functions.
Oliver:
I really appreciate the effort. However, the I had to make a change to make it run on 1.4 - add the layout manager and components not to the frame, but to its content pane. Are you using 1.5? The result also isn't resizable - making the window wider gives bigger borders, but making it narrower... well, just check it out.
Did you use a GUI builder for this? Which one? In a way, I think of it as "cheating", though I'm not sure why - but I know for realy world apps I'll have to use something like this, because laying out components manually really doesn't scale.
I wasn't even familiar with the acronym SSCCE, but I guess I posted one all the same!
The thing I'm afraid to ask about is SWT. Java already has AWT and swing, which is one GUI toolkit too many (and you can't really use swing by itself, can you? there's still AWT events and whatnots). And now I find out about a third one? Yikes! I'll go google it immediately.
Mark:
Because I was completely unfamiliar with Matisse, and netBeans (or anything else that's described as a "platform" makes my head hurt (it seems that way too many things related to Java have been described as "beans").
How would you describe netBeans in a couple of sentences? What's the relationship between Matisse and AWT/swing/SWT?
Oliver Wong - 13 Jun 2006 20:25 GMT > (replying to my own post, because it's a little better than replying > separately to all 3) [quoted text clipped - 5 lines] > looks like switching to a simpler manager actually solves most of the > problems. [...]
> Oliver: > > I really appreciate the effort. However, the I had to make a change to > make it run on 1.4 - add the layout manager and components not to the > frame, but to its content pane. Are you using 1.5? Yes.
> The result also > isn't resizable - making the window wider gives bigger borders, but > making it narrower... well, just check it out. Damn. I had window-resizing reaction working at one point, but then I made further changes and forgot to re-test. Oh well, it looks like Vova's solution is working for you, so I'll drop it for now.
> Did you use a GUI builder for this? Which one? In a way, I think of it > as "cheating", though I'm not sure why - but I know for realy world > apps I'll have to use something like this, because laying out > components manually really doesn't scale. No, this was manually written.
> I wasn't even familiar with the acronym SSCCE, but I guess I posted one > all the same! [quoted text clipped - 4 lines] > now I find out about a third one? Yikes! > I'll go google it immediately. http://www.eclipse.org/swt/
It's not included with a standard distribution of J2SE. It's the toolkit for Eclipse plugins though, and that's what I've been spending most of my time writing these days.
- Oliver
jackp@spambob.com - 13 Jun 2006 20:34 GMT > Damn. I had window-resizing reaction working at one point, but then I > made further changes and forgot to re-test. Oh well, it looks like Vova's > solution is working for you, so I'll drop it for now. Well, it works... but it's not resizable.
> No, this was manually written. Did you manually replace the include import javax.swing.* with all the individual classes?
Anyway, if there's no solution (which would be disappointing; I'm not think I'm asking for a lot of the layout managers) I have a backup plan: have a resize function that manually divides the window between the component the way I want to.
But it feels like a cop-out.
Oliver Wong - 13 Jun 2006 20:46 GMT >> No, this was manually written. > Did you manually replace the include import javax.swing.* with all the > individual classes? No, my IDE (Eclipse) does that for me.
> Anyway, if there's no solution (which would be disappointing; I'm not > think I'm asking for a lot of the layout managers) I have a backup > plan: have a resize function that manually divides the window between > the component the way I want to. > > But it feels like a cop-out. Did you consider Ian's solution of writing a custom layout manager?
- Oliver
IchBin - 13 Jun 2006 21:10 GMT >> Damn. I had window-resizing reaction working at one point, but then I >> made further changes and forgot to re-test. Oh well, it looks like Vova's [quoted text clipped - 11 lines] > > But it feels like a cop-out. Not to complicate things but you could do this with JGoodies Forms layout with no problem. I will build one and send to this forum.
http://www.jgoodies.com/freeware/forms/index.html
Thanks in Advance... IchBin, Pocono Lake, Pa, USA http://weconsultants.servebeer.com/JHackerAppManager __________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"' -William E. Taylor, Regular Guy (1952-)
jackp@spambob.com - 13 Jun 2006 21:13 GMT > Not to complicate things but you could do this with JGoodies Forms > layout with no problem. I will build one and send to this forum. > > http://www.jgoodies.com/freeware/forms/index.html Wow, yet another library to read...
I appreciate it, but it seems too much work to ask you to do - let me look into this myself, if I still need help, I'll be sure to let you know.
IchBin - 13 Jun 2006 23:06 GMT >> Not to complicate things but you could do this with JGoodies Forms >> layout with no problem. I will build one and send to this forum. [quoted text clipped - 6 lines] > look into this myself, if I still need help, I'll be sure to let you > know. Here is your program using JGoodies Forms layout.. I think this is what you wanted to do?
It is another library but it makes forms very easy to build. Much better that using Gridbag. You will need that Forms library to run. I am using forms-1.0.6.jar. Sorry I wrote it in my style.
import java.awt.event.ActionEvent; import java.awt.event.ActionListener;
import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextArea; import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities;
import com.jgoodies.forms.builder.DefaultFormBuilder; import com.jgoodies.forms.debug.FormDebugPanel; import com.jgoodies.forms.debug.FormDebugUtils; import com.jgoodies.forms.factories.ButtonBarFactory; import com.jgoodies.forms.layout.FormLayout;
public class LayoutProblem extends JFrame { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { new LayoutProblem(); } }); } public LayoutProblem() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); add(buildMainPanel()); pack(); setVisible(true); } private JPanel buildMainPanel() { FormLayout layout = new FormLayout( /* Columns */ "default:grow", /* Rows */ "pref, 12dlu, fill:0:grow(0.50), 6dlu, 20dlu, 6dlu, fill:0:grow(0.50)");
DefaultFormBuilder builder = DEBUGMODE ? new DefaultFormBuilder(layout,new FormDebugPanel()) : new DefaultFormBuilder(layout);
builder.setDefaultDialogBorder(); builder.setRowGroupingEnabled(true); builder.nextLine(2); builder.append(buildControl(jTable),1); builder.nextLine(2); builder.append(buildButtonBar()); builder.nextLine(2); builder.append(buildControl(jTextArea),1);
if (DEBUGMODE) { FormDebugUtils.dumpAll(builder.getPanel()); } return builder.getPanel(); } private JComponent buildButtonBar() { JPanel jPanel = new JPanel(); jPanel = ButtonBarFactory.buildCenteredBar( buildControl(BUTTON1), buildControl(BUTTON2), buildControl(BUTTON3), buildControl(BUTTON4)); jPanel.setBorder(BorderFactory.createRaisedBevelBorder()); return jPanel; } private JButton buildControl(String labelText) { jButton = new JButton(labelText); jButton.setName(labelText); jButton.setActionCommand(labelText); jButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jBotton_actionPerformed(e); } }); return jButton; } private JComponent buildControl(JTable jTable) { jTable = new JTable(dataValues, columnNames); JScrollPane scrollPane = new JScrollPane(jTable); jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); return scrollPane; } private JComponent buildControl(JTextArea jTextArea) { jTextArea = new JTextArea(logAreaHdr); JScrollPane scrollPane = new JScrollPane(jTextArea ); return scrollPane; } private void jBotton_actionPerformed(ActionEvent e) { final String method = "jBotton_actionPerformed(ActionEvent " + e + "): "; if (DEBUGMODE) { System.out.println(_Debugheader + method); }
if (BUTTON1.equals(e.getActionCommand())) { } else if (BUTTON2.equals(e.getActionCommand())) { } else if (BUTTON3.equals(e.getActionCommand())) { } else if (BUTTON4.equals(e.getActionCommand())) { } } private static final String _PROGRAM = (((new Throwable()).getStackTrace())[0].getClassName())+"."; protected static final String _Debugheader = "( DEBUG ) " + _PROGRAM; private static final boolean DEBUGMODE = true;
private JTable jTable; private JTextArea jTextArea; private JButton jButton;
private final String BUTTON1 = "Button 1"; private final String BUTTON2 = "Button 2"; private final String BUTTON3 = "Button 3"; private final String BUTTON4 = "Button 4"; private final String logAreaHdr = "---------------------------\n---------------------------\n---------------------------\n";
private final String columnNames[] = {"Column 1", "Column 2", "Column 3"}; private String dataValues[][] = { {"0aa", "bbb", "ccc"}, {"0dd", "eee", "fff"}, {"0gg", "hhh", "iii"}, {"1aa", "bbb", "ccc"}, {"1dd", "eee", "fff"}, {"1gg", "hhh", "iii"}, {"2aa", "bbb", "ccc"}, {"2dd", "eee", "fff"}, {"2gg", "hhh", "iii"}, {"3aa", "bbb", "ccc"}, {"3dd", "eee", "fff"}, {"3gg", "hhh", "iii"}, {"4aa", "bbb", "ccc"}, {"4dd", "eee", "fff"}, {"4gg", "hhh", "iii"}, {"5aa", "bbb", "ccc"}, {"5dd", "eee", "fff"}, {"5gg", "hhh", "iii"}, {"6aa", "bbb", "ccc"}, {"6dd", "eee", "fff"}, {"6gg", "hhh", "iii"}, {"7aa", "bbb", "ccc"}, {"7dd", "eee", "fff"}, {"7gg", "hhh", "iii"}, {"8aa", "bbb", "ccc"}, {"8dd", "eee", "fff"}, {"8gg", "hhh", "iii"}, {"9aa", "bbb", "ccc"}, {"9dd", "eee", "fff"}, {"9gg", "hhh", "iii"}, {"aaa", "bbb", "ccc"}, {"ddd", "eee", "fff"}, {"ggg", "hhh", "iii"},}; }
 Signature Thanks in Advance... IchBin, Pocono Lake, Pa, USA http://weconsultants.servebeer.com/JHackerAppManager __________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"' -William E. Taylor, Regular Guy (1952-)
IchBin - 13 Jun 2006 23:38 GMT >>> Not to complicate things but you could do this with JGoodies Forms >>> layout with no problem. I will build one and send to this forum. [quoted text clipped - 13 lines] > that using Gridbag. You will need that Forms library to run. I am using > forms-1.0.6.jar. Sorry I wrote it in my style. [snip code]
> private static final boolean DEBUGMODE = true; [snip code]
Forgot to mention to change the line above to false. This will stop displaying the red panel lines you use to determine how you want to layout your panel. Also will stop sending System.out information on the Forms layout debugging information.
Thanks in Advance... IchBin, Pocono Lake, Pa, USA http://weconsultants.servebeer.com/JHackerAppManager __________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"' -William E. Taylor, Regular Guy (1952-)
IchBin - 13 Jun 2006 22:59 GMT >>> Damn. I had window-resizing reaction working at one point, but >>> then I [quoted text clipped - 26 lines] > 'If there is one, Knowledge is the "Fountain of Youth"' > -William E. Taylor, Regular Guy (1952-) Here is your program using JGoodies Forms layout.. I think this is what you wanted to do?
import java.awt.event.ActionEvent; import java.awt.event.ActionListener;
import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextArea; import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities;
import com.jgoodies.forms.builder.DefaultFormBuilder; import com.jgoodies.forms.debug.FormDebugPanel; import com.jgoodies.forms.debug.FormDebugUtils; import com.jgoodies.forms.factories.ButtonBarFactory; import com.jgoodies.forms.layout.FormLayout;
public class LayoutProblem extends JFrame { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { new LayoutProblem(); } }); } public LayoutProblem() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); add(buildMainPanel()); pack(); setVisible(true); } private JPanel buildMainPanel() { FormLayout layout = new FormLayout( /* Columns */ "default:grow", /* Rows */ "pref, 12dlu, fill:0:grow(0.50), 6dlu, 20dlu, 6dlu, fill:0:grow(0.50)");
DefaultFormBuilder builder = DEBUGMODE ? new DefaultFormBuilder(layout,new FormDebugPanel()) : new DefaultFormBuilder(layout);
builder.setDefaultDialogBorder(); builder.setRowGroupingEnabled(true); builder.nextLine(2); builder.append(buildControl(jTable),1); builder.nextLine(2); builder.append(buildButtonBar()); builder.nextLine(2); builder.append(buildControl(jTextArea),1);
if (DEBUGMODE) { FormDebugUtils.dumpAll(builder.getPanel()); } return builder.getPanel(); } private JComponent buildButtonBar() { JPanel jPanel = new JPanel(); jPanel = ButtonBarFactory.buildCenteredBar( buildControl(BUTTON1), buildControl(BUTTON2), buildControl(BUTTON3), buildControl(BUTTON4)); jPanel.setBorder(BorderFactory.createRaisedBevelBorder()); return jPanel; } private JButton buildControl(String labelText) { jButton = new JButton(labelText); jButton.setName(labelText); jButton.setActionCommand(labelText); jButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jBotton_actionPerformed(e); } }); return jButton; } private JComponent buildControl(JTable jTable) { jTable = new JTable(dataValues, columnNames); JScrollPane scrollPane = new JScrollPane(jTable); jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); return scrollPane; } private JComponent buildControl(JTextArea jTextArea) { jTextArea = new JTextArea(logAreaHdr); JScrollPane scrollPane = new JScrollPane(jTextArea ); return scrollPane; } private void jBotton_actionPerformed(ActionEvent e) { final String method = "jBotton_actionPerformed(ActionEvent " + e + "): "; if (DEBUGMODE) { System.out.println(_Debugheader + method); }
if (BUTTON1.equals(e.getActionCommand())) { } else if (BUTTON2.equals(e.getActionCommand())) { } else if (BUTTON3.equals(e.getActionCommand())) { } else if (BUTTON4.equals(e.getActionCommand())) { } } private static final String _PROGRAM = (((new Throwable()).getStackTrace())[0].getClassName())+"."; protected static final String _Debugheader = "( DEBUG ) " + _PROGRAM; private static final boolean DEBUGMODE = true;
private JTable jTable; private JTextArea jTextArea; private JButton jButton;
private final String BUTTON1 = "Button 1"; private final String BUTTON2 = "Button 2"; private final String BUTTON3 = "Button 3"; private final String BUTTON4 = "Button 4"; private final String logAreaHdr = "---------------------------\n---------------------------\n---------------------------\n";
private final String columnNames[] = {"Column 1", "Column 2", "Column 3"}; private String dataValues[][] = { {"0aa", "bbb", "ccc"}, {"0dd", "eee", "fff"}, {"0gg", "hhh", "iii"}, {"1aa", "bbb", "ccc"}, {"1dd", "eee", "fff"}, {"1gg", "hhh", "iii"}, {"2aa", "bbb", "ccc"}, {"2dd", "eee", "fff"}, {"2gg", "hhh", "iii"}, {"3aa", "bbb", "ccc"}, {"3dd", "eee", "fff"}, {"3gg", "hhh", "iii"}, {"4aa", "bbb", "ccc"}, {"4dd", "eee", "fff"}, {"4gg", "hhh", "iii"}, {"5aa", "bbb", "ccc"}, {"5dd", "eee", "fff"}, {"5gg", "hhh", "iii"}, {"6aa", "bbb", "ccc"}, {"6dd", "eee", "fff"}, {"6gg", "hhh", "iii"}, {"7aa", "bbb", "ccc"}, {"7dd", "eee", "fff"}, {"7gg", "hhh", "iii"}, {"8aa", "bbb", "ccc"}, {"8dd", "eee", "fff"}, {"8gg", "hhh", "iii"}, {"9aa", "bbb", "ccc"}, {"9dd", "eee", "fff"}, {"9gg", "hhh", "iii"}, {"aaa", "bbb", "ccc"}, {"ddd", "eee", "fff"}, {"ggg", "hhh", "iii"},}; }
Thanks in Advance... IchBin, Pocono Lake, Pa, USA http://weconsultants.servebeer.com/JHackerAppManager __________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"' -William E. Taylor, Regular Guy (1952-)
Mark Space - 13 Jun 2006 21:51 GMT > Mark: > [quoted text clipped - 5 lines] > How would you describe netBeans in a couple of sentences? What's the > relationship between Matisse and AWT/swing/SWT? Matisse makes Swing objects, little classes that you can call new on, and setVisible, and they do all your display, layout and event firing for you.
Get NetBeans. (Get the latest one, 5.5) You don't need any plugins, everything is there for you already. Go through the tutorial below, it'll take about 30 minutes. If your eyes don't pop out of your head like Rodger Rabbit, then you can safely ignore it.
http://www.netbeans.org/kb/50/quickstart-gui.html
jackp@spambob.com - 13 Jun 2006 23:54 GMT > Get NetBeans. (Get the latest one, 5.5) You don't need any plugins, > everything is there for you already. Go through the tutorial below, > it'll take about 30 minutes. If your eyes don't pop out of your head > like Rodger Rabbit, then you can safely ignore it. > > http://www.netbeans.org/kb/50/quickstart-gui.html 60 MB - yikes. I'll download it tonight and play with it a little bit... and also try all the other suggestions. I'll try and post my conclusions tomorrow.
Again: Thanks, everybody!
IchBin - 14 Jun 2006 00:12 GMT >> Get NetBeans. (Get the latest one, 5.5) You don't need any plugins, >> everything is there for you already. Go through the tutorial below, [quoted text clipped - 8 lines] > > Again: Thanks, everybody! No the actual JGoodies Forms Library (forms-1.0.6.jar) is only *48kb*.
The complete Forms zip download, from http://www.jgoodies.com/downloads/libraries.html, is only *1.1MB*.
Also the last example, using gridbag from Steve, is still doing what Oliver did earlier today in his example.. That is, not expanding left to right and no 50% growth for the JTextArea and JTable each.
Thanks in Advance... IchBin, Pocono Lake, Pa, USA http://weconsultants.servebeer.com/JHackerAppManager __________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"' -William E. Taylor, Regular Guy (1952-)
IchBin - 14 Jun 2006 01:26 GMT >>> Get NetBeans. (Get the latest one, 5.5) You don't need any plugins, >>> everything is there for you already. Go through the tutorial below, [quoted text clipped - 6 lines] >> bit... and also try all the other suggestions. I'll try and post my >> conclusions tomorrow. [snip]
Just looked at the code again. It's ok but wanted to slim it down one more time..
import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener;
import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextArea; import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities;
import com.jgoodies.forms.builder.DefaultFormBuilder; import com.jgoodies.forms.debug.FormDebugPanel; import com.jgoodies.forms.debug.FormDebugUtils; import com.jgoodies.forms.factories.ButtonBarFactory; import com.jgoodies.forms.layout.FormLayout;
public class LayoutProblem implements ActionListener { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { new LayoutProblem(); } }); } public LayoutProblem() { jFrame.setDefaultCloseOperation(jFrame.EXIT_ON_CLOSE); jFrame.add(buildMainPanel()); jFrame.setPreferredSize(new Dimension(475,600)); jFrame.pack(); jFrame.setVisible(true); } private JPanel buildMainPanel() { FormLayout layout = new FormLayout ( /* Columns */ "default:grow", /* Rows */ "pref, 12dlu, fill:0:grow(0.50), 20dlu, fill:0:grow(0.50)" ); DefaultFormBuilder builder = DEBUGMODE ? new DefaultFormBuilder(layout,new FormDebugPanel()) : new DefaultFormBuilder(layout);
builder.setDefaultDialogBorder(); builder.nextLine(2); builder.append(buildControl(jTable)); builder.append(buildButtonBar()); builder.append(buildControl(jTextArea));
if (DEBUGMODE) { FormDebugUtils.dumpAll(builder.getPanel()); } return builder.getPanel(); } private JComponent buildButtonBar() { JPanel jPanel = new JPanel(); jPanel = ButtonBarFactory.buildCenteredBar( buildControl(BUTTON1), buildControl(BUTTON2), buildControl(BUTTON3), buildControl(TEXT_EXIT)); jPanel.setBorder(BorderFactory.createRaisedBevelBorder()); return jPanel; } private JButton buildControl(String labelText) { jButton = new JButton(labelText); jButton.addActionListener(this); return jButton; } private JComponent buildControl(JTable jTable) { jTable = new JTable(dataValues, columnNames); JScrollPane scrollPane = new JScrollPane(jTable); jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); return scrollPane; } private JComponent buildControl(JTextArea jTextArea) { jTextArea = new JTextArea(logAreaHdr); JScrollPane scrollPane = new JScrollPane(jTextArea ); return scrollPane; } public void actionPerformed(ActionEvent e) { final String method = "jBotton_actionPerformed(ActionEvent " + e + "): "; if (DEBUGMODE) { System.out.println(DEBUGHEATER + method); }
if (BUTTON1.equals(e.getActionCommand())) { } else if (BUTTON2.equals(e.getActionCommand())) { } else if (BUTTON3.equals(e.getActionCommand())) { } else if (TEXT_EXIT.equals(e.getActionCommand())) { System.exit(0); } }
private static final String PROGRAM = (((new Throwable()).getStackTrace())[0].getClassName())+"."; private static final String DEBUGHEATER = "( DEBUG ) " + PROGRAM; private static final boolean DEBUGMODE = false;
private JFrame jFrame = new JFrame("JGoodies Forms Layout Demo"); private JTable jTable; private JTextArea jTextArea; private JButton jButton;
private final String BUTTON1 = "Button 1"; private final String BUTTON2 = "Button 2"; private final String BUTTON3 = "Button 3"; private final String TEXT_EXIT = "EXIT"; private final String logAreaHdr = "---------------------------\n---------------------------\n---------------------------\n";
private final String columnNames[] = {"Column 1", "Column 2", "Column 3"}; private String dataValues[][] = { {"0aa", "bbb", "ccc"}, {"0dd", "eee", "fff"}, {"0gg", "hhh", "iii"}, {"1aa", "bbb", "ccc"}, {"1dd", "eee", "fff"}, {"1gg", "hhh", "iii"}, {"2aa", "bbb", "ccc"}, {"2dd", "eee", "fff"}, {"2gg", "hhh", "iii"}, {"3aa", "bbb", "ccc"}, {"3dd", "eee", "fff"}, {"3gg", "hhh", "iii"}, {"4aa", "bbb", "ccc"}, {"4dd", "eee", "fff"}, {"4gg", "hhh", "iii"}, {"5aa", "bbb", "ccc"}, {"5dd", "eee", "fff"}, {"5gg", "hhh", "iii"}, {"6aa", "bbb", "ccc"}, {"6dd", "eee", "fff"}, {"6gg", "hhh", "iii"}, {"7aa", "bbb", "ccc"}, {"7dd", "eee", "fff"}, {"7gg", "hhh", "iii"}, {"8aa", "bbb", "ccc"}, {"8dd", "eee", "fff"}, {"8gg", "hhh", "iii"}, {"9aa", "bbb", "ccc"}, {"9dd", "eee", "fff"}, {"9gg", "hhh", "iii"}, {"aaa", "bbb", "ccc"}, {"ddd", "eee", "fff"}, {"ggg", "hhh", "iii"},}; }
 Signature Thanks in Advance... IchBin, Pocono Lake, Pa, USA http://weconsultants.servebeer.com/JHackerAppManager __________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"' -William E. Taylor, Regular Guy (1952-)
IchBin - 14 Jun 2006 02:58 GMT >>> Get NetBeans. (Get the latest one, 5.5) You don't need any plugins, >>> everything is there for you already. Go through the tutorial below, [quoted text clipped - 17 lines] > Oliver did earlier today in his example.. That is, not expanding left to > right and no 50% growth for the JTextArea and JTable each. [snip]
Just looked at the code again. It's ok but wanted to slim it down one more time..
import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener;
import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextArea; import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities;
import com.jgoodies.forms.builder.DefaultFormBuilder; import com.jgoodies.forms.debug.FormDebugPanel; import com.jgoodies.forms.debug.FormDebugUtils; import com.jgoodies.forms.factories.ButtonBarFactory; import com.jgoodies.forms.layout.FormLayout;
public class LayoutProblem implements ActionListener { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { System.out.println(PROGRAM); new LayoutProblem(); } }); } public LayoutProblem() { jFrame.setDefaultCloseOperation(jFrame.EXIT_ON_CLOSE); jFrame.add(buildMainPanel()); jFrame.setPreferredSize(new Dimension(475,600)); jFrame.pack(); jFrame.setVisible(true); } private JComponent buildMainPanel() { FormLayout layout = new FormLayout ( /* Columns */ "default:grow", /* Rows */ "fill:0:grow(0.50), 20dlu, fill:0:grow(0.50)" ); DefaultFormBuilder builder = DEBUGMODE ? new DefaultFormBuilder(layout,new FormDebugPanel()) : new DefaultFormBuilder(layout);
builder.setDefaultDialogBorder(); builder.append(buildControl(jTable)); builder.append(buildButtonBar()); builder.append(buildControl(jTextArea));
if (DEBUGMODE) { FormDebugUtils.dumpAll(builder.getPanel()); } return builder.getPanel(); } private JComponent buildButtonBar() { JPanel jPanel = new JPanel(); jPanel = ButtonBarFactory.buildCenteredBar( buildControl(BUTTON1), buildControl(BUTTON2), buildControl(BUTTON3), buildControl(TEXT_EXIT)); jPanel.setBorder(BorderFactory.createRaisedBevelBorder()); return jPanel; } private JButton buildControl(String labelText) { jButton = new JButton(labelText); jButton.addActionListener(this); return jButton; } private JComponent buildControl(JTable jTable) { jTable = new JTable(dataValues, columnNames); JScrollPane scrollPane = new JScrollPane(jTable); jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); return scrollPane; } private JComponent buildControl(JTextArea jTextArea) { jTextArea = new JTextArea(logAreaHdr); JScrollPane scrollPane = new JScrollPane(jTextArea ); return scrollPane; } public void actionPerformed(ActionEvent e) { final String method = "jBotton_actionPerformed(ActionEvent " + e + "): "; if (DEBUGMODE) { System.out.println(DEBUGHEATER + method); }
if (BUTTON1.equals(e.getActionCommand())) { } else if (BUTTON2.equals(e.getActionCommand())) { } else if (BUTTON3.equals(e.getActionCommand())) { } else if (TEXT_EXIT.equals(e.getActionCommand())) { System.exit(0); } }
private static final String PROGRAM = (((new Throwable()).getStackTrace())[0].getClassName())+"."; private static final String DEBUGHEATER = "( DEBUG ) " + PROGRAM; private static final boolean DEBUGMODE = false;
private JFrame jFrame = new JFrame("JGoodies Forms Layout Demo"); private JTable jTable; private JTextArea jTextArea; private JButton jButton;
private final String BUTTON1 = "Button 1"; private final String BUTTON2 = "Button 2"; private final String BUTTON3 = "Button 3"; private final String TEXT_EXIT = "EXIT"; private final String logAreaHdr = "---------------------------\n---------------------------\n---------------------------\n";
private final String columnNames[] = {"Column 1", "Column 2", "Column 3"}; private String dataValues[][] = { {"0aa", "bbb", "ccc"}, {"0dd", "eee", "fff"}, {"0gg", "hhh", "iii"}, {"1aa", "bbb", "ccc"}, {"1dd", "eee", "fff"}, {"1gg", "hhh", "iii"}, {"2aa", "bbb", "ccc"}, {"2dd", "eee", "fff"}, {"2gg", "hhh", "iii"}, {"3aa", "bbb", "ccc"}, {"3dd", "eee", "fff"}, {"3gg", "hhh", "iii"}, {"4aa", "bbb", "ccc"}, {"4dd", "eee", "fff"}, {"4gg", "hhh", "iii"}, {"5aa", "bbb", "ccc"}, {"5dd", "eee", "fff"}, {"5gg", "hhh", "iii"}, {"6aa", "bbb", "ccc"}, {"6dd", "eee", "fff"}, {"6gg", "hhh", "iii"}, {"7aa", "bbb", "ccc"}, {"7dd", "eee", "fff"}, {"7gg", "hhh", "iii"}, {"8aa", "bbb", "ccc"}, {"8dd", "eee", "fff"}, {"8gg", "hhh", "iii"}, {"9aa", "bbb", "ccc"}, {"9dd", "eee", "fff"}, {"9gg", "hhh", "iii"}, {"aaa", "bbb", "ccc"}, {"ddd", "eee", "fff"}, {"ggg", "hhh", "iii"},}; }
Thanks in Advance... IchBin, Pocono Lake, Pa, USA http://weconsultants.servebeer.com/JHackerAppManager __________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"' -William E. Taylor, Regular Guy (1952-)
IchBin - 14 Jun 2006 03:20 GMT >>> Get NetBeans. (Get the latest one, 5.5) You don't need any plugins, >>> everything is there for you already. Go through the tutorial below, [quoted text clipped - 17 lines] > Oliver did earlier today in his example.. That is, not expanding left to > right and no 50% growth for the JTextArea and JTable each. [snip]
Just looked at the code again. It's ok but wanted to slim it down one more time..
import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener;
import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextArea; import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities;
import com.jgoodies.forms.builder.DefaultFormBuilder; import com.jgoodies.forms.debug.FormDebugPanel; import com.jgoodies.forms.debug.FormDebugUtils; import com.jgoodies.forms.factories.ButtonBarFactory; import com.jgoodies.forms.layout.FormLayout;
public class LayoutProblem implements ActionListener { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { new LayoutProblem(); } }); } public LayoutProblem() { jFrame.setDefaultCloseOperation(jFrame.EXIT_ON_CLOSE); jFrame.add(buildMainPanel()); jFrame.setPreferredSize(new Dimension(475,600)); jFrame.pack(); jFrame.setVisible(true); } private JComponent buildMainPanel() { FormLayout layout = new FormLayout ( /* Columns */ "default:grow", /* Rows */ "fill:0:grow(0.50), 20dlu, fill:0:grow(0.50)" ); DefaultFormBuilder builder = DEBUGMODE ? new DefaultFormBuilder(layout,new FormDebugPanel()) : new DefaultFormBuilder(layout);
builder.setDefaultDialogBorder(); builder.append(buildControl(jTable)); builder.append(buildButtonBar()); builder.append(buildControl(jTextArea));
if (DEBUGMODE) { FormDebugUtils.dumpAll(builder.getPanel()); } return builder.getPanel(); } private JComponent buildButtonBar() { JPanel jPanel = new JPanel(); jPanel = ButtonBarFactory.buildCenteredBar( buildControl(BUTTON1), buildControl(BUTTON2), buildControl(BUTTON3), buildControl(TEXT_EXIT)); jPanel.setBorder(BorderFactory.createRaisedBevelBorder()); return jPanel; } private JButton buildControl(String labelText) { jButton = new JButton(labelText); jButton.addActionListener(this); return jButton; } private JComponent buildControl(JTable jTable) { jTable = new JTable(dataValues, columnNames); jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); return new JScrollPane(jTable); } private JComponent buildControl(JTextArea jTextArea) { jTextArea = new JTextArea(logAreaHdr); return new JScrollPane(jTextArea ); } public void actionPerformed(ActionEvent e) { final String method = "jBotton_actionPerformed(ActionEvent " + e + "): "; if (DEBUGMODE) { System.out.println(DEBUGHEATER + method); }
if (BUTTON1.equals(e.getActionCommand())) { } else if (BUTTON2.equals(e.getActionCommand())) { } else if (BUTTON3.equals(e.getActionCommand())) { } else if (TEXT_EXIT.equals(e.getActionCommand())) { System.exit(0); } }
private static final String PROGRAM = (((new Throwable()).getStackTrace())[0].getClassName())+"."; private static final String DEBUGHEATER = "( DEBUG ) " + PROGRAM; private static final boolean DEBUGMODE = false;
private JFrame jFrame = new JFrame("JGoodies Forms Layout Demo"); private JTable jTable; private JTextArea jTextArea; private JButton jButton;
private final String BUTTON1 = "Button 1"; private final String BUTTON2 = "Button 2"; private final String BUTTON3 = "Button 3"; private final String TEXT_EXIT = "EXIT"; private final String logAreaHdr = "---------------------------\n---------------------------\n---------------------------\n";
private final String columnNames[] = {"Column 1", "Column 2", "Column 3"}; private String dataValues[][] = { {"0aa", "bbb", "ccc"}, {"0dd", "eee", "fff"}, {"0gg", "hhh", "iii"}, {"1aa", "bbb", "ccc"}, {"1dd", "eee", "fff"}, {"1gg", "hhh", "iii"}, {"2aa", "bbb", "ccc"}, {"2dd", "eee", "fff"}, {"2gg", "hhh", "iii"}, {"3aa", "bbb", "ccc"}, {"3dd", "eee", "fff"}, {"3gg", "hhh", "iii"}, {"4aa", "bbb", "ccc"}, {"4dd", "eee", "fff"}, {"4gg", "hhh", "iii"}, {"5aa", "bbb", "ccc"}, {"5dd", "eee", "fff"}, {"5gg", "hhh", "iii"}, {"6aa", "bbb", "ccc"}, {"6dd", "eee", "fff"}, {"6gg", "hhh", "iii"}, {"7aa", "bbb", "ccc"}, {"7dd", "eee", "fff"}, {"7gg", "hhh", "iii"}, {"8aa", "bbb", "ccc"}, {"8dd", "eee", "fff"}, {"8gg", "hhh", "iii"}, {"9aa", "bbb", "ccc"}, {"9dd", "eee", "fff"}, {"9gg", "hhh", "iii"}, {"aaa", "bbb", "ccc"}, {"ddd", "eee", "fff"}, {"ggg", "hhh", "iii"},}; }
Thanks in Advance... IchBin, Pocono Lake, Pa, USA http://weconsultants.servebeer.com/JHackerAppManager __________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"' -William E. Taylor, Regular Guy (1952-)
Ian Shef - 13 Jun 2006 20:15 GMT <text deleted that described a layout problem that MAY have a simple solution using EXISTING java components and layout managers>
> I'm that close to using absolute positioning, calculating the sizes > manually whenever the window's resized, but what's the right way? Feel > free to point out my stupid mistakes, and/or suggest sweeping changes, > As long as the app behaves the way it should (or close to it) that's > really enough for me. If you can't figure out a solution using existing components and layout managers, write your own layout manager.
If you already know how to do the calculations for the sizes and the absolute positions, then writing your own layout manager is easy to do.
<source code example deleted>
 Signature Ian Shef 805/F6 * These are my personal opinions Raytheon Company * and not those of my employer. PO Box 11337 * Tucson, AZ 85734-1337 *
jackp@spambob.com - 13 Jun 2006 21:58 GMT > If you can't figure out a solution using existing components and layout > managers, write your own layout manager. > > If you already know how to do the calculations for the sizes and the absolute > positions, then writing your own layout manager is easy to do. Well, I'm not sure that a full layout manager is called for, since it's just for this one frame, with these specific components. I'll look into it too, though. Thanks.
steve - 13 Jun 2006 22:56 GMT >> If you can't figure out a solution using existing components and layout >> managers, write your own layout manager. [quoted text clipped - 6 lines] > just for this one frame, with these specific components. I'll look into > it too, though. Thanks. there is usually a multitude of ways to do things.
here is your layout , as i think you wanted it , including resize!! the text area really does not look too good, full length of the window, so i have adjusted it, also this code will resize smaller, than the previous examples and retain some semblance of what is in it.
pls note when resizing, the areas will jump about and not maintain the ratio , i don't know how you want it but you just need to play about with the weights for each area
steve
//~--- JDK imports ------------------------------------------------------------
import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets;
import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextArea; import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities;
//~--- classes ----------------------------------------------------------------
public class LayoutProblem extends JFrame { String columnNames[] = {"Column 1", "Column 2", "Column 3"}; String dataValues[][] = { {"0aa", "bbb", "ccc"}, {"0dd", "eee", "fff"}, {"0gg", "hhh", "iii"}, {"1aa", "bbb", "ccc"}, {"1dd", "eee", "fff"}, {"1gg", "hhh", "iii"}, {"2aa", "bbb", "ccc"}, {"2dd", "eee", "fff"}, {"2gg", "hhh", "iii"}, {"3aa", "bbb", "ccc"}, {"3dd", "eee", "fff"}, {"3gg", "hhh", "iii"}, {"4aa", "bbb", "ccc"}, {"4dd", "eee", "fff"}, {"4gg", "hhh", "iii"}, {"5aa", "bbb", "ccc"}, {"5dd", "eee", "fff"}, {"5gg", "hhh", "iii"}, {"6aa", "bbb", "ccc"}, {"6dd", "eee", "fff"}, {"6gg", "hhh", "iii"}, {"7aa", "bbb", "ccc"}, {"7dd", "eee", "fff"}, {"7gg", "hhh", "iii"}, {"8aa", "bbb", "ccc"}, {"8dd", "eee", "fff"}, {"8gg", "hhh", "iii"}, {"9aa", "bbb", "ccc"}, {"9dd", "eee", "fff"}, {"9gg", "hhh", "iii"}, {"aaa", "bbb", "ccc"}, {"ddd", "eee", "fff"}, {"ggg", "hhh", "iii"}, }; JTable table = new JTable(dataValues, columnNames); JScrollPane scrollPane = new JScrollPane(table); private JTextArea jTextArea1 = new JTextArea(); private JPanel jPanel2 = new JPanel(); private JPanel jPanel1 = new JPanel(); private JButton jButton4 = new JButton(); private JButton jButton3 = new JButton(); private JButton jButton2 = new JButton(); private JButton jButton1 = new JButton(); private GridBagLayout gridBagLayout1 = new GridBagLayout();
//~--- constructors -------------------------------------------------------
public LayoutProblem() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jTextArea1.setText( "---------------------------\n---------------------------\n------- --------------------\n"); jbInit(); pack(); setVisible(true); }
//~--- methods ------------------------------------------------------------
private void jbInit() { this.getContentPane().setLayout(new GridBagLayout()); this.setSize(new Dimension(663, 380)); jButton1.setText("jButton1"); jButton2.setText("jButton2"); jButton3.setText("jButton3"); jButton4.setText("jButton4"); jPanel2.setLayout(gridBagLayout1); scrollPane.getViewport().add(table, null); this.getContentPane().add(scrollPane, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); jPanel1.add(jButton1, null); jPanel1.add(jButton2, null); jPanel1.add(jButton3, null); jPanel1.add(jButton4, null); this.getContentPane().add(jPanel1, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jPanel2.add(jTextArea1, new GridBagConstraints(0, 0, GridBagConstraints.REMAINDER, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 27, 5, 0), 0, 0)); this.getContentPane().add(jPanel2, new GridBagConstraints(0, 2, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 6, 0, 46), 0, 0)); }
public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { new LayoutProblem(); } }); } }
Karsten Lentzsch - 13 Jun 2006 23:10 GMT > <text deleted that described a layout problem that MAY have a simple solution > using EXISTING java components and layout managers> > [...] > If you can't figure out a solution using existing components and layout > managers, write your own layout manager. Right. I just like to add that there exist layout managers that handle huge classes of screen design, for example the ExplicitLayout, or even better the ExplicitLayout plus Explicit Table Builder.
I can do all my screen design with existing layout managers - at the form level. And I write custom layout managers only at the component level, for example to lay out combobox parts.
It seems to me that many developers think that writing a custom layout manager is difficult; it is not. But it's difficult to write a custom layout manager that lays out forms that follow the MS Layout specifications and guidelines, because it is based on Dialog Units, not pixel, where basic Java has only pixels as unit.
-Karsten
jackp@spambob.com - 14 Jun 2006 15:57 GMT > Right. I just like to add that there exist layout managers > that handle huge classes of screen design, for example > the ExplicitLayout, or even better the ExplicitLayout plus > Explicit Table Builder. Ladies and gentlemen, I do believe we have a winner.
import com
|
|