我使用NetBeans IDE创建了此表。问题是,如果它有超过20行,它只显示那20行。其他行未显示,也不会滚动。
它只显示表格中最后一行的一半(见图)。
我更改了滚动窗格的宽度和高度,并将表格放在另一个滚动窗格中,但这不起作用。
此代码由NetBeans生成。
spStockItems.setAutoscrolls(真); 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
Ledger No“,”From to Ledger“,”Full Item Code“,”Unit Price“,”Item 输入“,”GRN类型“,”StockID“,”AnnRP“,”停止“,”百分比“ } ){ boolean [] canEdit = new boolean [] { false,false,false,false,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);
答案 0 :(得分:3)
摆脱......
spStockItems.setMinimumSize(new java.awt.Dimension(452, 300));
spStockItems.setPreferredSize(new java.awt.Dimension(452, 300));
和...
tblStockItems.setMinimumSize(new java.awt.Dimension(452, 300));
tblStockItems.setPreferredSize(new java.awt.Dimension(452, 300));
这些与JScrollPane
确定表格何时需要滚动的方式紧密相关。
学习如何使用布局管理器,并且不要害怕在多个组件中使用多个布局来构建UI。
花点时间学习手工编写您的用户界面,它会让您更好地了解它的内容以及表单编辑器的限制(以及何时使用它们)