How can I set a JLabel's background and border the same as a table header?

前端 未结 4 912
无人共我
无人共我 2021-01-15 12:53

I want to recreate a table header looks using JLabel. The look and feel of the JLabel needs to be exactly like the JTableHeader would

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-15 13:50

    I figured I'll create a JTable without any rows and place a JTextPane right underneath. And it works like charm.

    JTextPane textPane = new JTextPane();
    JPanel panel = new JPanel(new BorderLayout());
    
    JTable table = new JTable(0, 1);
    table.setPreferredScrollableViewportSize(new Dimension(600, 0));
    JScrollPane js = new JScrollPane(table)
    
    panel.add(js, BorderLayout.NORTH);
    panel.add(new JScrollPane(textPane),BorderLayout.CENTER);
    

提交回复
热议问题