Re: Drawing columns headers of a JTable
On Aug 6, 1:09 am, Chanchal <chanchal.ja...@gmail.com> wrote:
Actually what i want to develop is a table like this
http://picasaweb.google.com/chanchal.jacob/Java/photo#523104972145407...
Screenshots! Great gear. A picture speaks a
thousand words, no?
(snip)
I have user JTable rather than 'tame-table' to reduce complexity of
this example.
I notice. That code was also a very good description
of the *immediate* problem of the table header not
appearing (that is the current problem, right?).
You are going to swear when you see how close you
were to seeing that header.. ;)
<sscce>
import java.awt.*;
import javax.swing.*;
public class TableColumHeaderTest extends JFrame{
public TableColumHeaderTest() {
// I have to call this - matter of habit..
setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
setLayout(new BorderLayout());
Object[][] headerData = {{"H1","H2"},{"H3","H4"}};
Object[][] dataData = {{"D1","D2"},{"D3","D4"}};
Object[] tempHead = {"th","th"};
JTable headerTable = new JTable(headerData,tempHead);
JTable dataTable = new JTable(dataData,tempHead);
// it is rarely necessary to call setVisible()!
// (excepting root components)
//dataTable.getTableHeader().setVisible(false);
JScrollPane scrollPane = new JScrollPane(dataTable);
scrollPane.setColumnHeaderView(headerTable);
scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER,
headerTable);
getContentPane().add(BorderLayout.CENTER, scrollPane);
pack();
}
public static void main(String[] args){
TableColumHeaderTest t = new TableColumHeaderTest();
t.setSize(400,300);
t.setVisible(true);
}
}
</sscce>
HTH
--
Andrew Thompson
http://pscode.org/