Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2007

Tip: Looking for answers? Try searching our database.

invisible JTable headers

Thread view: 
mehafi@gmail.com - 23 Aug 2007 18:00 GMT
Hi,
Does someone know why headers of this table doesn't appears?

import java.awt.*;
import javax.swing.*;

public class TestTable {
 public static void main(String[] argum) {

   String[] Headers = new String[] {"Number", "New?", "Origin",
"Destination", "Produced", "Weight" };
   Object[][] Data = new Object[][]
   {
     { "100420", Boolean.FALSE, "Des Moines IA", "Spokane WA",
"02/06/2000", new Float(450) },
     { "202174", Boolean.TRUE, "Basking Ridge NJ", "Princeton NJ",
"05/20/2000", new Float(1250) },
     { "450877", Boolean.TRUE, "St. Paul MN", "Austin TX",
"03/20/2000",
new Float(1745) },
     { "101891", Boolean.FALSE, "Boston MA", "Albany NY",
"04/04/2000", new
Float(88) }
   };

   JTable Tab = new JTable(Data, Headers);

   JFrame Frame = new JFrame("TestTable");
   Frame.getContentPane().add( Tab );
   Frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
   Frame.setSize(500, 200);
   Frame.setVisible(true);
 }
}

Interesting, that when I put this table into JScrollPane, headers
appears:

Frame.getContentPane().add( new JScrollPane( Tab ) );

But it doesn't works in simple JPanel. Is it necesary putting table
into
JScrollPane?

thanks in advane
Joshua Cranmer - 23 Aug 2007 18:34 GMT
> Hi,
> Does someone know why headers of this table doesn't appears?

By default, the headers of a JTable only show when put into a
JScrollPane; there is a method somewhere that can be used to get the
header part of the table.

> Interesting, that when I put this table into JScrollPane, headers
> appears:
[quoted text clipped - 4 lines]
> into
> JScrollPane?

Typically, it works several times easier to put into a scroll pane; most
people expect large tables to scroll; this won't happen without a scroll
pane.

If you want to use a JTable without a JScrollPane, then you can use
getTableHeader().

> thanks in advane

Signature

Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth

Lew - 23 Aug 2007 18:41 GMT
mehafi@gmail.com wrote:
>> Interesting, that when I put this table into JScrollPane, headers
>> appears:
>>
>> Frame.getContentPane().add( new JScrollPane( Tab ) );

By pretty much universal convention, Java method, instance and local variable
names should begin with a lower-case letter and be written in camelCase
thereafter, class and interface names (including annotations) begin with an
upper-case letter and CamelCase thereafter, either way without underscores,
and public static final compile-time constants are written in all upper-case
letters, with underscores separating the compound word parts.

Signature

Lew



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.