Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > invisible JTable headers

Reply
Thread Tools

invisible JTable headers

 
 
mehafi@gmail.com
Guest
Posts: n/a
 
      08-23-2007
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(8 }
};

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

 
Reply With Quote
 
 
 
 
Joshua Cranmer
Guest
Posts: n/a
 
      08-23-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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:
>
> Frame.getContentPane().add( new JScrollPane( Tab ) );
>
> But it doesn't works in simple JPanel. Is it necesary putting table
> 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
>



--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      08-23-2007
(E-Mail Removed) 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.

--
Lew
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Making 1 control invisible while showing another in the exact location of the invisible one Andy B ASP .Net 5 05-29-2008 03:08 AM
Invisible - Succinic acid : (AMBER ACID) Invisible krithika.143@gmail.com C++ 0 04-14-2008 06:59 PM
Putting a JTable inside a JTable cell? Tivo Escobar Java 1 04-12-2007 11:09 AM
How to move data from a CSV file to a JTable, and from a JTable to a CSV file ? Tintin92 Java 1 02-14-2007 06:51 PM
Invisible column in JTable Ike Java 2 08-22-2003 02:25 PM



Advertisments