Question

I drag jtabel from palette and i try to customize the code for multi-line header but in table it's not showed.sorry for my ugly English. thanks in advance

jTable1=new javax.swing.JTable(); 

jTable1.setModel(new javax.swing.table.DefaultTableModel(
    new Object [][] {

        {null, null, null, null},
        {null, null, null, null},
        {null, null, null, null},
        {null, null, null, null}
    },
    new String [] {
        "", "Title 2", "Title 3", "Title 4"
    }
));

jScrollPane4.setViewportView(jTable1);

jTable1.getColumnModel().getColumn(0).setHeaderValue("poa\nsfh");
Was it helpful?

Solution

The default renderers in Swing use a JLabel to render the text. A JLabel doesn't not recognize the "\n" String.

A JLabel can display HTML, so you can try using HTML for the heading. Read the section from the Swing tutorial on How to Use HTML in Swing Components for more information.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top