 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Kenneth P. Turvey Guest
|
Posted: Thu May 03, 2007 10:17 pm Post subject: Using panels |
|
|
I'm writing a small program for my own use and I've run into a problem I
don't completely understand. I don't have a lot of experience with Swing
and it is a big API, so please forgive the simplicity of the solution that
I'm sure exists.
In the application I wish to have a single pane split into three parts
with each part covered by a panel (or maybe a scrollpane) that holds the
actual components. These components are added dynamically at run time
based on the internal state of the program.
Unfortunately when I add a panel to the panel that sits in the split pane
I don't see anything. There isn't an error or an exception, just no
display. I've played around with it a bit, but I can't seem to get it to
work.
I've put together a small example that uses two classes that shows the
problem I'm having. I'll include the classes below. These were put
together in NetBeans so they are a little bit more complex than necessary,
but the added complexity can be ignored for the most part.
The basic problem is that I'm adding the ChoreHeaderPanel to the jPanel1
and I'm not getting anything in the display.
Thanks.
--
Kenneth P. Turvey <kt-usenet (AT) squeakydolphin (DOT) com>
XMPP: kpturvey (AT) jabber (DOT) org
-------------------------------------------------------------------------
/*
* PanelTest.java
*
* Created on May 2, 2007, 6:47 PM
*/
package com.squeakydolphin.tokentracker;
import javax.swing.JPanel;
/**
*
* @author kt
*/
public class PanelTest extends javax.swing.JFrame {
/** Creates new form PanelTest */
public PanelTest() {
initComponents();
JPanel panel = new ChoreHeaderPanel();
jPanel1.add(panel);
jPanel1.validate();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jSplitPane1 = new javax.swing.JSplitPane();
jPanel1 = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 314, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 298, Short.MAX_VALUE)
);
jSplitPane1.setRightComponent(jPanel1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jSplitPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 427, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jSplitPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new PanelTest().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JPanel jPanel1;
private javax.swing.JSplitPane jSplitPane1;
// End of variables declaration
}
-------------------------------------------------------
/*
* ChoreHeaderPanel.java
*
* Created on May 1, 2007, 12:20 PM
*/
package com.squeakydolphin.tokentracker;
/**
*
* @author kt
*/
public class ChoreHeaderPanel extends javax.swing.JPanel {
/** Creates new form ChoreHeaderPanel */
public ChoreHeaderPanel() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
setMinimumSize(new java.awt.Dimension(100, 35));
jLabel1.setText("Chores");
jLabel2.setText("Red");
jLabel3.setText("White");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(50, 50, 50)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, 0)
.addComponent(jLabel3)
.addContainerGap(304, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel1))
.addContainerGap(18, Short.MAX_VALUE))
);
}// </editor-fold>
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
// End of variables declaration
} |
|
| Back to top |
|
 |
Andrew Thompson Guest
|
Posted: Fri May 04, 2007 5:58 am Post subject: Re: Using panels |
|
|
Kenneth P. Turvey wrote:
..
| Quote: | Unfortunately when I add a panel to the panel that sits in the split pane
I don't see anything.
|
validate() or possibly repaint() might fix it, but..
...
| Quote: | I've put together a small example that uses two classes that shows the
problem I'm having. I'll include the classes below.
|
They are not included, but ..*.
| Quote: | ...These were put
together in NetBeans ..
|
"Don't blame us for your software" and..
| Quote: | ..so they are a little bit more complex than necessary,
but the added complexity can be ignored for the most part.
|
Why the heck should we 'ignore' the unnecessary complexity?
Why, instead, do you not *remove* it so we never have to suffer
the bandwidth, or take (any) efforts to 'ignore' it ourselves!
* If you actually need to post code, please do us the courtesy
of posting the *smallest* code example that shows the problem.
--
Andrew Thompson
http://www.athompson.info/andrew/
Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-gui/200705/1 |
|
| Back to top |
|
 |
Kenneth P. Turvey Guest
|
Posted: Fri May 04, 2007 6:39 am Post subject: Re: Using panels |
|
|
On Fri, 04 May 2007 00:58:37 +0000, Andrew Thompson wrote:
| Quote: | Kenneth P. Turvey wrote:
.
Unfortunately when I add a panel to the panel that sits in the split pane
I don't see anything.
d
validate() or possibly repaint() might fix it, but..
|
I tried validate(). It doesn't help. Actually it might be in the
included source.
| Quote: |
..
I've put together a small example that uses two classes that shows the
problem I'm having. I'll include the classes below.
They are not included, but ..*.
|
Actually they are. Right below the signature.
| Quote: |
...These were put
together in NetBeans ..
"Don't blame us for your software" and..
|
NetBeans doesn't do anything strange with the classes. I checked.
| Quote: |
..so they are a little bit more complex than necessary, but the added
complexity can be ignored for the most part.
Why the heck should we 'ignore' the unnecessary complexity? Why, instead,
do you not *remove* it so we never have to suffer the bandwidth, or take
(any) efforts to 'ignore' it ourselves! * If you actually need to post
code, please do us the courtesy of posting the *smallest* code example
that shows the problem.
|
If you had looked at the classes you would have found them to be quite
small, but complete. I added the warning more out of courtesy than out of
necessity.
You really should look at the code before spinning off on these kinds of
tangents. Now we have two complete messages devoted to a few lines of
extra code in the classes.
--
Kenneth P. Turvey <kt-usenet (AT) squeakydolphin (DOT) com>
XMPP: kpturvey (AT) jabber (DOT) org |
|
| Back to top |
|
 |
Knute Johnson Guest
|
Posted: Fri May 04, 2007 6:48 am Post subject: Re: Using panels |
|
|
Kenneth P. Turvey wrote:
| Quote: | On Fri, 04 May 2007 00:58:37 +0000, Andrew Thompson wrote:
Kenneth P. Turvey wrote:
.
Unfortunately when I add a panel to the panel that sits in the split pane
I don't see anything.
d
validate() or possibly repaint() might fix it, but..
I tried validate(). It doesn't help. Actually it might be in the
included source.
..
I've put together a small example that uses two classes that shows the
problem I'm having. I'll include the classes below.
They are not included, but ..*.
Actually they are. Right below the signature.
...These were put
together in NetBeans ..
"Don't blame us for your software" and..
NetBeans doesn't do anything strange with the classes. I checked.
..so they are a little bit more complex than necessary, but the added
complexity can be ignored for the most part.
Why the heck should we 'ignore' the unnecessary complexity? Why, instead,
do you not *remove* it so we never have to suffer the bandwidth, or take
(any) efforts to 'ignore' it ourselves! * If you actually need to post
code, please do us the courtesy of posting the *smallest* code example
that shows the problem.
If you had looked at the classes you would have found them to be quite
small, but complete. I added the warning more out of courtesy than out of
necessity.
You really should look at the code before spinning off on these kinds of
tangents. Now we have two complete messages devoted to a few lines of
extra code in the classes.
|
I don't know what Andrew is using for a reader but in Thunderbird it is
almost impossible to read your code after the signature. That is a
TBird problem but...
Your program is not as simple as it really needs to be but here is one
issue I've found.
JPanel panel = new ChoreHeaderPanel();
jPanel1.add(panel);
jPanel1.validate();
You are adding panel to jPanel1 but not to it's layout. Also I know
that the IDEs love GroupLayout but it is a pain to read and understand.
Why is panel not added in initComponents()? I think part of your
problem is calling add() on jPanel1 and not addComponent() on its
layout. And since we are talking about IDEs does it add the variable
declarations at the end of the class file or is that author's choice?
--
Knute Johnson
email s/nospam/knute/ |
|
| Back to top |
|
 |
Andrew Thompson Guest
|
Posted: Fri May 04, 2007 7:11 am Post subject: Re: Using panels |
|
|
Knute Johnson wrote:
| Quote: | .
Unfortunately when I add a panel to the panel that sits in the split pane
..
...Now we have two complete messages devoted to a few lines of
extra code in the classes.
I don't know what Andrew is using for a reader but in Thunderbird it is
almost impossible to read your code after the signature.
|
Oops! My 'software' (a certain OS component using a
web interface to usenet) *hides* sigs. with a little '+'
to exapnd them - I fogot to check under the sig., and
did not see the code..
...
| Quote: | Your program is not as simple as it really needs ...
|
Too true. Here is my simplified version..
<sscce>
import java.awt.*;
import javax.swing.*;
public class PanelTest extends JFrame {
/** Creates new form PanelTest */
public PanelTest() {
initComponents();
validate();
}
private void initComponents() {
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Container c = getContentPane();
JSplitPane jSplitPane1 = new
JSplitPane(
JSplitPane.HORIZONTAL_SPLIT,
new JLabel("left"),
new ChoreHeaderPanel());
c.setLayout(new BorderLayout());
c.add( jSplitPane1, BorderLayout.CENTER );
pack();
}
public static void main(String args[]) {
EventQueue.invokeLater(new Runnable() {
public void run() {
new PanelTest().setVisible(true);
}
});
}
}
class ChoreHeaderPanel extends JPanel {
public ChoreHeaderPanel() {
initComponents();
}
private void initComponents() {
jLabel1 = new JLabel();
jLabel2 = new JLabel();
jLabel3 = new JLabel();
setBorder(BorderFactory.createLineBorder(new Color(0, 0, 0)));
setMinimumSize(new Dimension(100, 35));
jLabel1.setText("Chores");
jLabel2.setText("Red");
jLabel3.setText("White");
GroupLayout layout = new GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1,
GroupLayout.PREFERRED_SIZE,
76,
GroupLayout.PREFERRED_SIZE)
.addGap(50, 50, 50)
.addComponent(jLabel2,
GroupLayout.PREFERRED_SIZE,
37,
GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, 0)
.addComponent(jLabel3)
.addContainerGap(304, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.
BASELINE)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel1))
.addContainerGap(18, Short.MAX_VALUE))
);
}// </editor-fold>
private JLabel jLabel1;
private JLabel jLabel2;
private JLabel jLabel3;
}
</sscce>
..and. What was the question again?
The main problem seemed to be all those dang
GroupLayouts - I don't know what you intend putting
into the split pane panels, but I think you need to
get each root component validated and on-screen
seperately, before trying to put it in a further layout
that goes into the split pane!
--
Andrew Thompson
http://www.athompson.info/andrew/
Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-gui/200705/1 |
|
| Back to top |
|
 |
Brandon McCombs Guest
|
Posted: Sat May 05, 2007 7:11 am Post subject: Re: Using panels |
|
|
Knute Johnson wrote:
| Quote: | Kenneth P. Turvey wrote:
On Fri, 04 May 2007 00:58:37 +0000, Andrew Thompson wrote:
Kenneth P. Turvey wrote:
.
Unfortunately when I add a panel to the panel that sits in the split
pane
I don't see anything.
d
validate() or possibly repaint() might fix it, but..
I tried validate(). It doesn't help. Actually it might be in the
included source.
..
I've put together a small example that uses two classes that shows the
problem I'm having. I'll include the classes below.
They are not included, but ..*.
Actually they are. Right below the signature.
...These were put
together in NetBeans ..
"Don't blame us for your software" and..
NetBeans doesn't do anything strange with the classes. I checked.
..so they are a little bit more complex than necessary, but the added
complexity can be ignored for the most part.
Why the heck should we 'ignore' the unnecessary complexity? Why,
instead,
do you not *remove* it so we never have to suffer the bandwidth, or take
(any) efforts to 'ignore' it ourselves! * If you actually need to post
code, please do us the courtesy of posting the *smallest* code example
that shows the problem.
If you had looked at the classes you would have found them to be quite
small, but complete. I added the warning more out of courtesy than
out of
necessity.
You really should look at the code before spinning off on these kinds of
tangents. Now we have two complete messages devoted to a few lines of
extra code in the classes.
|
Threads involving Andrew often spiral into conversations such as the one
you just experienced. It is due to him complaining more about your
presentation than just ignoring the fact it wasn't perfect or wasn't the
way he would have done it and just helping w/o making such remarks. I
believe the number of useful sentences he produces are overshadowed by
how many non-useful sentences he produces. Wear a flak jacket so you are
always prepared for his responses.
| Quote: |
I don't know what Andrew is using for a reader but in Thunderbird it is
almost impossible to read your code after the signature. That is a
TBird problem but...
|
Using TBird 2.0 on a 19" screen the code is perfectly readable for me.
Only 2 lines wrap (the setHorizontalGroup/setVerticalGroup lines within
his initComponent() method).
| Quote: |
Your program is not as simple as it really needs to be but here is one
issue I've found.
|
He shall be hanged for this abomination, then disemboweled. That will
teach him.
| Quote: |
JPanel panel = new ChoreHeaderPanel();
jPanel1.add(panel);
jPanel1.validate();
You are adding panel to jPanel1 but not to it's layout. Also I know
that the IDEs love GroupLayout but it is a pain to read and understand.
Why is panel not added in initComponents()? I think part of your
problem is calling add() on jPanel1 and not addComponent() on its
layout. And since we are talking about IDEs does it add the variable
declarations at the end of the class file or is that author's choice?
|
|
|
| Back to top |
|
 |
Kenneth P. Turvey Guest
|
Posted: Sun May 06, 2007 4:36 am Post subject: Re: Using panels |
|
|
On Thu, 03 May 2007 18:48:09 -0700, Knute Johnson wrote:
[Snip]
| Quote: | You are adding panel to jPanel1 but not to it's layout. Also I know that
the IDEs love GroupLayout but it is a pain to read and understand.
Why is panel not added in initComponents()? I think part of your
problem is calling add() on jPanel1 and not addComponent() on its layout.
And since we are talking about IDEs does it add the variable declarations
at the end of the class file or is that author's choice?
|
Looking at it after reading this I switched to using the Box layout and
simplified things a bit. That solved the problem. I'm still unsure of
why the panel didn't show up, but the problem is solved. I have decided
that using the group layout that the IDE selects by default is probably a
bad idea unless there is some reason to justify it. The other layouts
probably handle most tasks without a problem.
Thanks.
--
Kenneth P. Turvey <kt-usenet (AT) squeakydolphin (DOT) com>
XMPP: kpturvey (AT) jabber (DOT) org |
|
| Back to top |
|
 |
Kenneth P. Turvey Guest
|
Posted: Sun May 06, 2007 4:38 am Post subject: Re: Using panels |
|
|
On Fri, 04 May 2007 04:35:56 +0000, Andrew Thompson wrote:
[Snip]
| Quote: | The main problem seemed to be all those dang GroupLayouts - I don't know
what you intend putting into the split pane panels, but I think you need
to get each root component validated and on-screen seperately, before
trying to put it in a further layout that goes into the split pane!
|
Yeah, that was it. I've changed to using a box layout and it all works
now. Thanks for your help.
--
Kenneth P. Turvey <kt-usenet (AT) squeakydolphin (DOT) com>
XMPP: kpturvey (AT) jabber (DOT) org |
|
| 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
|
|