儘管我已將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中的新項目中。編譯乾淨,運行它看問題。 –