我使用NetBeans IDE創建了此表。問題是,如果它有超過20行,它只顯示那20行。其他行不顯示,不會滾動。
它只顯示錶格中最後一行的一半(見圖片)。
我改變了滾動窗格的寬度和高度,我把表放在另一個滾動窗格中,但這不起作用。
此代碼是從NetBeans生成的。
spStockItems.setAutoscrolls(true); spStockItems.setMinimumSize(new java.awt.Dimension(452,300)); spStockItems.setPreferredSize(new java.awt.Dimension(452,300));
tblStockItems.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N tblStockItems.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null} }, new String [] { "Item Name", "Ref. No.", "Available Qty.", "Unit", "Ledger No.", "Sup ID", "Raw Price", "Item Code", "Ref. ID.", "Full
萊傑否」, 「從到總帳」, 「全項目碼」, 「單價」, 「項目 類型」, 「GRN類型」, 「StockID」, 「AnnRP」, 「停止」 ,「百分比」 } ){ boolean [] canEdit = new boolean [] { false,false,false,false,false,false,false,false,false ,FALSE,FALSE, FALSE,FALSE };
public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit [columnIndex]; } }); tblStockItems.setMinimumSize(new java.awt.Dimension(452, 300)); tblStockItems.setPreferredSize(new java.awt.Dimension(452, 300)); tblStockItems.setRowHeight(14); spStockItems.setViewportView(tblStockItems); tblStockItems.getColumnModel().getColumn(0).setPreferredWidth(250); tblStockItems.getColumnModel().getColumn(4).setMinWidth(0); tblStockItems.getColumnModel().getColumn(4).setPreferredWidth(0); tblStockItems.getColumnModel().getColumn(4).setMaxWidth(0);
參見[如何使用scrollpanes](http://docs.oracle.com/javase/tutorial/uiswing/components/scrollpane.html),你需要將'JTable'添加到'JScrollPane'中,而不是混淆'preferred/minimum/'JTable'的最大尺寸' – MadProgrammer
您如何期待這裏的任何人修復您不顯示的破損代碼?注意:在這種情況下,代碼比截圖更有用。爲了更快地獲得更好的幫助,請發佈** [MCVE](http://stackoverflow.com/help/mcve)(最小完整和可驗證示例)**。 –
@AndrewThompson就像我們做每一個答案,巫毒! – MadProgrammer