Re: tables and table headers

Dennis Ponos <[email protected]> 24 Jan 2005 15:08:39 -0800
Newsgroups gmane.comp.embedded.carlsbad-cubes
Message-ID <[email protected]>
D'oh!  I can't believe I overlooked the scroll pane and wasted your
time.  That was indeed the problem. 

Thank you so much for looking into such a trivial matter. 



On Mon, 2005-01-24 at 14:43, Frank Meissner wrote:
> Dennis Ponos wrote:
> > Thank you for replying to my question, Frank. 
> > 
> > First, let me make sure I understand you correctly.  Are you saying that
> > you DON't use the <tableheader> tag?  That's what it sounds like, but I
> > want to make sure. 
> 
> That is correct. Up to your question, I did not know the tag existed at 
> all ;)
> 
> > 
> > Second, my tablemodel class is extending DefaultTableModel, so it was
> > returning the right values in getColumnCount() and getColumnName().  I
> > stepped through the code in debug mode to make sure.  Even so, I
> > implemented the methods in my tablemodel class so I would have an
> > example like yours.
> 
> It took me a while but you need to put the table in a scrollpane:
> <?xml version="1.0" encoding="UTF-8" ?>
> <frame id="frame" title="Test Table" size="360,200" >
>    <panel id="pnl_North" layout="borderlayout"
> 		constraints="BorderLayout.CENTER">
> <scrollpane>
>     <table initclass="DNSTableModel"/>
> </scrollpane>
>    </panel>
> </frame>
> 
> 
> To make your program work, I did change a few things
> public class Tables extends WindowAdapter {
>    private Tables() {
>      SwingEngine swix;
>      try {
>        swix = new SwingEngine( this );
>        Container c = swix.render( "xml/tabletest.xml" );
>        c.setVisible(true);
>        //      swix.getRootComponent().setVisible(true);
>        if( c instanceof Window) {
>          ((Window)c).addWindowListener(this);
>        }
>      } catch (Exception e) {
>        e.printStackTrace();
>      }
>    }
> 
>    /**
>     * Invoked when the user attempts to close the window
>     * from the window's system menu.  If the program does not
>     * explicitly hide or dispose the window while processing
>     * this event, the window close operation will be cancelled.
>     */
>    public void windowClosing(WindowEvent e) {
>      System.out.println( "Good Bye!" );
>      super.windowClosing(e);
>      System.exit( 0 );
>    }
> 
> I can send you the complete source files, if you have any further 
> difficulties.
> 
> Frank
> > 
> > I made these changes but I am still not able to get the table header
> > displayed :-( 
> > 
> > I must be missing something really fundamental and stupid. 
> > 
> > Here is my simple XML file.... 
> > 
> > <?xml version="1.0" encoding="UTF-8" ?>
> > <frame id="frame" title="Test Table" size="360,200" >
> >   <panel id="pnl_North" layout="borderlayout"         
> > 		constraints="BorderLayout.NORTH">
> >    <table initclass="DNSTableModel"/>
> >   </panel>
> > </frame>
> > 
> > 
> > And here is my tablemodel class...... 
> > 
> > 
> > public class DNSTableModel extends DefaultTableModel {
> >   /**
> >    * Constructs a DefaultTableModel object.
> >    */
> >   public DNSTableModel() {
> >     super();
> >     String[] columnNames = {"Name",
> >             "E-mail Address",
> >             "Comments"};
> >     addColumn(columnNames[0]);
> >     addColumn(columnNames[1]);
> >     addColumn(columnNames[2]);
> >     
> >     Object[][] data = {
> >             {"admin", "[email protected]","First Administrator"},
> >              {"dponos", "[email protected]","Best Administrator"}
> >     };
> >     addRow(data[0]);
> >     addRow(data[1]);
> >     
> >   }
> >   
> >   public int getColumnCount() {
> >       
> >       //this line of code is from the superclass
> >       int s = columnIdentifiers.size();
> >       
> >       //added this just in case 
> >       System.out.println("columns =" + s);
> >       return 3;
> >   }
> > 
> >   public String getColumnName(int column) {
> >       
> >      //these lines of code are from the superclass. They work fine. 
> >      Object id = null; 
> >      String col; 
> >      if (column < columnIdentifiers.size()) {  
> >         id = columnIdentifiers.elementAt(column); 
> >      }
> >      col = (id == null) ? super.getColumnName(column) 
> >                           : id.toString();
> >      
> >      //added these lines just in case.....
> >       System.out.println(col);
> >       switch (column) {
> >           case 1:
> >               return "Name";
> >           case 2:
> >               return "E-mail address";
> >           case 3:
> >               return "Comments";
> >           default:
> >               return null;
> >       }
> >   }
> > 
> > 
> > And here is my application classl mostly copied from Actions.java in the
> > samples.... 
> > 
> >   private Tables() {
> >     try {
> >       swix = new SwingEngine( this );
> >       swix.render( "xml/tables.xml" );
> >       swix.getRootComponent().setVisible(true);
> >     } catch (Exception e) {
> >       e.printStackTrace();
> >     }
> >   }
> > 
> >   /**
> >    * Invoked when the user attempts to close the window
> >    * from the window's system menu.  If the program does not
> >    * explicitly hide or dispose the window while processing
> >    * this event, the window close operation will be cancelled.
> >    */
> >   public void windowClosing(WindowEvent e) {
> >     System.out.println( "Good Bye!" );
> >     super.windowClosing(e);
> >     System.exit( 0 );
> >   }
> > 
> >   //
> >   //  Make the class bootable
> >   //
> > 
> >   public static void main(String[] args) {
> >     new Tables();
> >   }
> > }
> > 
> > 
> > 
> > On Mon, 2005-01-24 at 01:17, [email protected] wrote:
> > 
> >>List for Users of Carlsbad Cubes' Technologies and Products <[email protected]> schrieb am 23.01.05 19:53:02:
> >>
> >>>I am having difficulty getting table headers to show up in the GUI.  I
> >>>have a table that I am initializing through a table model.  That part is
> >>>working just fine. 
> >>>
> >>>I tried using the tableheader tag, and initializing it using a
> >>>tablecolumnmodel.
> >>
> >>I usually use code like this in my tablemodel:
> >>    public int getColumnCount() {
> >>        return ...;
> >>    }
> >>
> >>     /* (non-Javadoc)
> >>     * @see javax.swing.table.AbstractTableModel#getColumnName(int)
> >>     */
> >>    public String getColumnName(int column) {
> >>        switch (column) {
> >>        case ...:
> >>            return ...;
> >>        case ...:
> >>            return ...;
> >>        default:
> >>            return null;
> >>        }
> >>    }
> >>
> >>Works like a charme ;)
> >>
> >>
> >>>I also tried not using a tableheader tag, and adding columns to the
> >>>tablemodel. 
> >>
> >>Never had to use this, so I cannot help you there...
> >>
> >>Frank
> >>
> >>>Any help on this subject would be greatly appreciated. 
> >>>
> >>>
> >>>
> >>>
> >>>_______________________________________________
> >>>Forum mailing list
> >>>[email protected]
> >>>http://carlsbadcubes.com/mailman/listinfo/forum_carlsbadcubes.com
> >>
> >>
> >>
> >>
> >>_______________________________________________
> >>Forum mailing list
> >>[email protected]
> >>http://carlsbadcubes.com/mailman/listinfo/forum_carlsbadcubes.com
> > 
> > 
> > 
> > _______________________________________________
> > Forum mailing list
> > [email protected]
> > http://carlsbadcubes.com/mailman/listinfo/forum_carlsbadcubes.com
> > 
> 
> 
> _______________________________________________
> Forum mailing list
> [email protected]
> http://carlsbadcubes.com/mailman/listinfo/forum_carlsbadcubes.com