Re: Layout problem driving me insane - panels, resizing, etc
IchBin wrote:
jackp@spambob.com wrote:
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.
[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"},};
}
--
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-)