Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #1569 > unrolled thread
| Started by | "Kenneth P. Turvey" <kenneth.p..turvey@THRWHITE.remove-dii-this> |
|---|---|
| First post | 2011-04-27 15:34 +0000 |
| Last post | 2011-04-27 15:34 +0000 |
| Articles | 8 — 4 participants |
Back to article view | Back to comp.lang.java.gui
Using panels "Kenneth P. Turvey" <kenneth.p..turvey@THRWHITE.remove-dii-this> - 2011-04-27 15:34 +0000
Re: Using panels "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:34 +0000
Re: Using panels "Kenneth P. Turvey" <kenneth.p..turvey@THRWHITE.remove-dii-this> - 2011-04-27 15:34 +0000
Re: Using panels "Knute Johnson" <knute.johnson@THRWHITE.remove-dii-this> - 2011-04-27 15:34 +0000
Re: Using panels "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:34 +0000
Re: Using panels "Kenneth P. Turvey" <kenneth.p..turvey@THRWHITE.remove-dii-this> - 2011-04-27 15:34 +0000
Re: Using panels "Brandon McCombs" <brandon.mccombs@THRWHITE.remove-dii-this> - 2011-04-27 15:34 +0000
Re: Using panels "Kenneth P. Turvey" <kenneth.p..turvey@THRWHITE.remove-dii-this> - 2011-04-27 15:34 +0000
| From | "Kenneth P. Turvey" <kenneth.p..turvey@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:34 +0000 |
| Subject | Using panels |
| Message-ID | <pan.2007.05.02.23.58.41.49676@squeakydolphin.com> |
To: comp.lang.java.gui
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@squeakydolphin.com>
XMPP: kpturvey@jabber.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
}
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [next] | [standalone]
| From | "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:34 +0000 |
| Message-ID | <71a618c816e0c@uwe> |
| In reply to | #1569 |
To: comp.lang.java.gui Kenneth P. Turvey wrote: . >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.. .. >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 ..*. >...These were put >together in NetBeans .. "Don't blame us for your software" and.. >..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 --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Kenneth P. Turvey" <kenneth.p..turvey@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:34 +0000 |
| Message-ID | <pan.2007.05.04.01.36.48.558735@squeakydolphin.com> |
| In reply to | #1570 |
To: comp.lang.java.gui 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. -- Kenneth P. Turvey <kt-usenet@squeakydolphin.com> XMPP: kpturvey@jabber.org --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Knute Johnson" <knute.johnson@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:34 +0000 |
| Message-ID | <thw_h.112005$cJ1.110482@newsfe13.lga> |
| In reply to | #1571 |
To: comp.lang.java.gui
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.
>
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/
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:34 +0000 |
| Message-ID | <71a7febeb54bc@uwe> |
| In reply to | #1572 |
To: comp.lang.java.gui
Knute Johnson wrote:
>>> .
>>>> 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..
..
>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
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Kenneth P. Turvey" <kenneth.p..turvey@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:34 +0000 |
| Message-ID | <pan.2007.05.05.23.38.33.221593@squeakydolphin.com> |
| In reply to | #1573 |
To: comp.lang.java.gui On Fri, 04 May 2007 04:35:56 +0000, Andrew Thompson wrote: [Snip] > 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@squeakydolphin.com> XMPP: kpturvey@jabber.org --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Brandon McCombs" <brandon.mccombs@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:34 +0000 |
| Message-ID | <463c0fc2$0$5785$4c368faf@roadrunner.com> |
| In reply to | #1572 |
To: comp.lang.java.gui Knute Johnson wrote: > 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. > > 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). > > 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. > > 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? > --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Kenneth P. Turvey" <kenneth.p..turvey@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:34 +0000 |
| Message-ID | <pan.2007.05.05.23.36.24.362870@squeakydolphin.com> |
| In reply to | #1572 |
To: comp.lang.java.gui On Thu, 03 May 2007 18:48:09 -0700, Knute Johnson wrote: [Snip] > 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@squeakydolphin.com> XMPP: kpturvey@jabber.org --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.gui
csiph-web