 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Griffith Jones Guest
|
Posted: Wed Jun 14, 2006 1:18 am Post subject: Re: MVC Framework for Swing? |
|
|
Much thanks for the references, Karsten. Ditto the excellent tool library
....
Griff Jones
"Karsten Lentzsch" <karsten (AT) jgoodies (DOT) com> wrote in message
news:e6n2f7$5d4$01$1 (AT) news (DOT) t-online.com...
| Quote: | Griffith Jones wrote:
I'm looking for an MVC framework for Swing apps. I'm thinking of
something similar to Struts, but for desktop apps. I keep on writing
controllers for each Swing app I develope, and I can't believe there's
not a framework out there to expedite this.
I suggest you check out the MVP and "Presentation Model"
patterns. Just google "Organizing Presentation Logic",
and you'll get a reference to a narrative by Martin Fowler
where he motivates MVP and Presentation Model.
I've found that a good understanding of these patterns
helps every project, where in contrast other techniques
like automatic databinding can increase or decrease your
productivity.
Once you're familiar with these patterns, you may choose
a helper library or framework that follows one of these
approaches.
I provide presentation about desktop patterns and
data binding at http://www.jgoodies.com/articles/
and a free open source helper library for working
with the Presentation Model pattern in Swing:
the JGoodies Binding. But as said in the slides,
automatic data binding is a wild horse that may
be difficult to ride on.
-Karsten |
|
|
| Back to top |
|
 |
Mark Space Guest
|
Posted: Wed Jun 14, 2006 1:51 am Post subject: Re: Layout problem driving me insane - panels, resizing, etc |
|
|
jackp (AT) spambob (DOT) com wrote:
| Quote: |
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?
|
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 |
|
| Back to top |
|
 |
Guest
|
Posted: Wed Jun 14, 2006 1:58 am Post subject: Re: Layout problem driving me insane - panels, resizing, etc |
|
|
| Quote: | 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. |
|
| Back to top |
|
 |
steve Guest
|
Posted: Wed Jun 14, 2006 2:56 am Post subject: Re: Layout problem driving me insane - panels, resizing, etc |
|
|
On Wed, 14 Jun 2006 04:58:50 +0800, jackp (AT) spambob (DOT) com wrote
(in article <1150232330.207863.87570 (AT) c74g2000cwc (DOT) googlegroups.com>):
| Quote: | 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.
|
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();
}
});
}
} |
|
| Back to top |
|
 |
IchBin Guest
|
Posted: Wed Jun 14, 2006 2:59 am Post subject: Re: Layout problem driving me insane - panels, resizing, etc |
|
|
IchBin wrote:
| Quote: | jackp (AT) spambob (DOT) com wrote:
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.
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-)
|
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-) |
|
| Back to top |
|
 |
IchBin Guest
|
Posted: Wed Jun 14, 2006 3:06 am Post subject: Re: Layout problem driving me insane - panels, resizing, etc |
|
|
jackp (AT) spambob (DOT) com wrote:
| Quote: | 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.
|
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"},};
}
--
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-) |
|
| Back to top |
|
 |
Karsten Lentzsch Guest
|
Posted: Wed Jun 14, 2006 3:10 am Post subject: Re: Layout problem driving me insane - panels, resizing, etc |
|
|
Ian Shef wrote:
| Quote: | jackp (AT) spambob (DOT) com wrote in
news:1150220142.633907.41210 (AT) f6g2000cwb (DOT) googlegroups.com:
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 |
|
| Back to top |
|
 |
IchBin Guest
|
Posted: Wed Jun 14, 2006 3:38 am Post subject: Re: Layout problem driving me insane - panels, resizing, etc |
|
|
IchBin wrote:
| Quote: | jackp (AT) spambob (DOT) com wrote:
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.
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.
|
[snip code]
| Quote: | 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-) |
|
| Back to top |
|
 |
Guest
|
Posted: Wed Jun 14, 2006 3:54 am Post subject: Re: Layout problem driving me insane - panels, resizing, etc |
|
|
| Quote: | 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! |
|
| Back to top |
|
 |
IchBin Guest
|
Posted: Wed Jun 14, 2006 4:12 am Post subject: Re: Layout problem driving me insane - panels, resizing, etc |
|
|
jackp (AT) spambob (DOT) com wrote:
| Quote: | 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!
|
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-) |
|
| Back to top |
|
 |
IchBin Guest
|
Posted: Wed Jun 14, 2006 5:26 am Post subject: Re: Layout problem driving me insane - panels, resizing, etc |
|
|
IchBin wrote:
| Quote: | jackp (AT) spambob (DOT) 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-) |
|
| Back to top |
|
 |
IchBin Guest
|
Posted: Wed Jun 14, 2006 6:58 am Post subject: Re: Layout problem driving me insane - panels, resizing, etc |
|
|
IchBin wrote:
| Quote: | jackp (AT) spambob (DOT) 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.
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.
|
[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-) |
|
| Back to top |
|
 |
IchBin Guest
|
Posted: Wed Jun 14, 2006 7:10 am Post subject: Re: Layout problem driving me insane - panels, resizing, etc |
|
|
IchBin wrote:
| Quote: | jackp (AT) spambob (DOT) 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.
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.
|
[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-) |
|
| Back to top |
|
 |
Thomas Weidenfeller Guest
|
Posted: Wed Jun 14, 2006 12:48 pm Post subject: Re: MVC Framework for Swing? |
|
|
Griffith Jones wrote:
| Quote: | I'm looking for Swing app frameworks, if you know of any ...
|
I haven't followed java app framework development closely. So some of
the stuff in the list below no longer exist or is not suited. Anyhow,
you might want to have a look at JLense, Kanabos, Pustefix, Merlin,
Jaffa, Pulpitum, JGoodies, JUICe, or Atris Framework. Oh, and both
Netbeans and Eclipse (the IDEs) do have some RCP (rich client platform).
The NetBeans Rich Client Platform and the Eclipse Rich Client Platform
respectively.
Sun is also going to standardize an app framework in JSR 296, related to
http://wiki.java.net/bin/view/Javadesktop/SwingLabs. But that will take
some time, and it will be a committee compromise.
There is also stuff like SwiXML or XUI for the XML-everywhere fanboys.
/Thomas
--
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/ |
|
| Back to top |
|
 |
Guest
|
Posted: Wed Jun 14, 2006 7:57 pm Post subject: Re: Layout problem driving me insane - panels, resizing, etc |
|
|
Karsten Lentzsch wrote:
| Quote: | 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.zookitec.layout.*;
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);
// table
table = new JTable(dataValues, columnNames);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JScrollPane tableScrollPane = new JScrollPane(table);
// button panel
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);
// text area
logArea = new JTextArea();
logArea.setText("---------------------------\n---------------------------\n---------------------------\n");
JScrollPane logAreaScrollPane = new JScrollPane(logArea);
// and now, the magic begins
Container cont = getContentPane(); // for Java 1.4
cont.setLayout(new ExplicitLayout());
cont.add(buttonPanel, new ExplicitConstraints(
buttonPanel,
ContainerEF.centerX(cont),
ContainerEF.centerY(cont),
ContainerEF.width(cont),
MathEF.constant(40),
0.5, 0.5, true, true
));
cont.add(tableScrollPane, new ExplicitConstraints(
tableScrollPane,
ContainerEF.left(cont),
ContainerEF.top(cont),
ContainerEF.width(cont),
true,
MathEF.subtract(ComponentEF.top(buttonPanel), PADDING),
false
));
cont.add(logAreaScrollPane, new ExplicitConstraints(
logAreaScrollPane,
ContainerEF.left(cont),
MathEF.add(ComponentEF.bottom(buttonPanel), PADDING),
ContainerEF.width(cont),
true,
ContainerEF.bottom(cont),
false
));
pack();
setSize(450,600); // initial app size
setVisible(true);
}
}
This layout manager is exactly what I've been looking for - I don't
think I'll ever use gridbaglayout again. IchBin's JGoodies solution
looks great too, but since I already spent way too much time on this, I
wanted to go with a standalone, layout manager only solution - and
since IchBin's already solved the problem with JGoodies there wasn't
any more fun to be had that way.
I still need to install eclipse and look at SWT and netBeans, and
probably the other JGoodies, but it seems at least as far as layout
managers are concerned, I'm all set.
Again: Thanks, everybody. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|