尽管我已将setResizingAllowed()
设置为true
,但我无法通过在标题列之间移动光标并拖动分隔线来调整列宽。JTable Swing:我无法通过在标题中拖动光标来调整列的大小
tbResumen = new JTable();
tbResumen.setEnabled(false);
tbResumen.setRowHeight(20);
tbResumen.setBackground(UIManager.getColor("Table.selectionBackground"));
tbResumen.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
tbResumen.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
tbResumen.setFont(new Font("Arial", Font.PLAIN, 12));
tbResumen.setDefaultRenderer(Object.class, new RenderTablaInfo());
tbResumen.setOpaque(false);
tbResumen.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
tbResumen.setColumnSelectionAllowed(false);
tbResumen.setRowSelectionAllowed(true);
tbResumen.setSize(new Dimension(840, 450));
tbResumen.setPreferredScrollableViewportSize(new Dimension(840, 450));
tbResumen.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
tbResumen.setModel(new DefaultTableModel(new Object[][] {{ label1, label2, label3, label4} },
new String[] { "foo", "bar", "foobar", "barfoo" }));
final JTableHeader headerResumen = new JTableHeader();
headerResumen.setReorderingAllowed(false);
headerResumen.setResizingAllowed(true);
headerResumen.setColumnModel(tbResumen.getColumnModel());
headerResumen.setTable(tbResumen);
tbResumen.setTableHeader(headerResumen);
如果有人需要更多代码来澄清情况,我会尽快添加它们。谢谢。
*“任何想法?”*为了更好地提供帮助,请张贴[MCVE]或[简短,独立,正确的示例](http://www.sscce.org/)。 –
阅读链接后编辑问题。如果之后有任何想法......谢谢。 – FaithReaper
你显然不明白链接,因为不可编译的代码片段可能是M,但不是C,V或E的问题。请注意,如果真正需要制作完整,可编译和可运行的示例,则适当的MCVE可能为150 LOC。一个好的MCVE测试如下。将'MCVE'粘贴到IDE中的新项目中。编译干净,运行它看问题。 –