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");
有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top