代码之家  ›  专栏  ›  技术社区  ›  Morgan

删除JTable(Windows LaF)中的单元格编辑器边框

  •  0
  • Morgan  · 技术社区  · 7 年前

    enter image description here

    有没有办法将其删除,使其看起来与此类似?

    enter image description here

    1 回复  |  直到 7 年前
        1
  •  2
  •   camickr    7 年前

    创建表后,您可以尝试以下操作:

    DefaultCellEditor editor = (DefaultCellEditor)table.getDefaultEditor(Object.class);
    JTextField textField = (JTextField)editor.getComponent();
    textField.setBorder( null );
    

    编辑:

    上述方法不起作用,因为JTable使用 GenericEditor 它是表的内部类,扩展了DefaultCellEditor,并为表添加了额外的功能。

    添加的一项功能是管理边框:“红色”表示错误,“黑色”表示有效数据。因此,编辑器会不断重置边界。

    或者另一种方法是:

    JTextField textField = new JTextField();
    textField.setBorder( null );
    DefaultCellEditor editor = new DefaultCellEditor( textField );
    table.setDefaultEditor(Object.class, editor):