问题描述
- JScrollPane 的水平滚动条不显示啦,急求大伙看下
-
DefaultTableModel model = new DefaultTableModel(datas, columns); JTable table = new CommonJTable(model); //表格大小 table.setPreferredSize(new Dimension(1200, 800)); //选中行颜色 table.setSelectionBackground(Color.yellow); //不拖动 table.getTableHeader().setReorderingAllowed(false); DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();// 设置table内容居中 tcr.setHorizontalAlignment(SwingConstants.CENTER);// table.setDefaultRenderer(Object.class, tcr); FitTableColumns(table); JScrollPane upPane = new JScrollPane(); upPane.setViewportView(table); upPane.setPreferredSize(new Dimension(800,700)); upPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); upPane.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); upPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); table.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);// 水平滚动条 JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, top, upPane); this.add(split);
解决方案
在
upPane.setPreferredSize(new Dimension(800,700));
前加一句
upPane.setSize(800, 700);
试试
时间: 2024-10-22 02:55:08