如何删除默认边框以及如何锚定jtable的列标题?

时间:2014-11-12 17:11:48

标签: java swing jtable border jtabbedpane

this is my question

您好。

我想删除scollpane的边框和

我不想在我拖动时允许列标题移动它。

请救救我

提前致谢

    import java.awt.BorderLayout;
    import javax.swing.*;
    import javax.swing.table.DefaultTableModel;

    class mf extends JFrame{

        public mf(){

            this.setSize(444, 444);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            Object[] haha = new Object[]{"list"};
            DefaultTableModel model = new DefaultTableModel(haha, 0);

            model.addRow(new Object[]{"don't try hit me and hit me"});
            model.addRow(new Object[]{"free your mind"});
            JTable wow = new JTable(model);
            wow.setAutoCreateRowSorter(true);

            JScrollPane jesus = new JScrollPane(wow);


            JTabbedPane jt = new JTabbedPane();
            jt.addTab("no way", jesus);

            this.add(jt, BorderLayout.NORTH);

           this.setVisible(true);
        }
    }
    public class Test extends JFrame{
      public static void main(String[] args){
          new mf();}}

1 个答案:

答案 0 :(得分:1)

要禁止移动列标题,您可以使用wow.getTableHeader().setReorderingAllowed(false);

要删除Border,请使用:

JScrollPane jesus = new JScrollPane(wow);
jesus.setBorder(null);