Path: csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!news.alt.net!news-in-01.newsfeed.easynews.com!easynews.com!easynews!news-out.news.tds.net!newsreading01.news.tds.net!86597e80!not-for-mail From: "Kenneth P. Turvey" Subject: Using panels Message-ID: X-Comment-To: comp.lang.java.gui Newsgroups: comp.lang.java.gui Content-Type: text/plain; charset=IBM437 Content-Transfer-Encoding: 8bit X-Gateway: time.synchro.net [Synchronet 3.15a-Win32 NewsLink 1.92] Lines: 188 Date: Wed, 27 Apr 2011 15:34:05 GMT NNTP-Posting-Host: 96.60.20.240 X-Complaints-To: news@tds.net X-Trace: newsreading01.news.tds.net 1303918445 96.60.20.240 (Wed, 27 Apr 2011 10:34:05 CDT) NNTP-Posting-Date: Wed, 27 Apr 2011 10:34:05 CDT Organization: TDS.net Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.gui:1569 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 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. */ // 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(); }// /** * @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. */ // 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)) ); }// // 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