为什么Jscrollpane添加Jtable后没有滚动条
有些并不重要的代码就删除了,显示效果见图privateJTablegoodsTable;JPanelgroundPanel;JScrollPanescrollPane;p...
有些并不重要的代码就删除了,显示效果见图
private JTable goodsTable; JPanel groundPanel; JScrollPane scrollPane; private void initGUI() { pack(); setSize(240, 300); groundPanel=new JPanel(); groundPanel.setLocale(null); groundPanel.setOpaque(false); groundPanel.setBounds(0, 0, 240, 200); scrollPane = new JScrollPane(); TableModel goodsTableModel = new DefaultTableModel( new String[][] { { "One", "Two","Three" }, { "Three","Three", "Four" }, { "Three", "Four","2" } , { "Three","Three", "Four" }, { "Three","Three", "Four" }, { "Three","Three", "Four" } , { "Three","Three", "Four" }, { "Three","Three", "Four" }, { "Three","Three", "Four" } }, new String[] { "Column 1", "Column 2", "Column 3" }); goodsTable = new JTable(); goodsTable.setModel(goodsTableModel); goodsTable.addMouseListener(new MyMouseAdapter()); scrollPane.setViewportView(goodsTable); scrollPane.setBounds(0, 0, 240, 200); scrollPane.setSize(240,120); groundPanel.add(scrollPane); groundPanel.setPreferredSize(new Dimension(240, 200)); add(groundPanel); }
知道了,没有超过默认的出现滚动条行数。Dimension a=new Dimension();
a.height=80;
a.width=200;
goodsTable.setPreferredScrollableViewportSize(a);
给其他遇见类似问题的人一点帮助吧。
谁来领积分 展开
private JTable goodsTable; JPanel groundPanel; JScrollPane scrollPane; private void initGUI() { pack(); setSize(240, 300); groundPanel=new JPanel(); groundPanel.setLocale(null); groundPanel.setOpaque(false); groundPanel.setBounds(0, 0, 240, 200); scrollPane = new JScrollPane(); TableModel goodsTableModel = new DefaultTableModel( new String[][] { { "One", "Two","Three" }, { "Three","Three", "Four" }, { "Three", "Four","2" } , { "Three","Three", "Four" }, { "Three","Three", "Four" }, { "Three","Three", "Four" } , { "Three","Three", "Four" }, { "Three","Three", "Four" }, { "Three","Three", "Four" } }, new String[] { "Column 1", "Column 2", "Column 3" }); goodsTable = new JTable(); goodsTable.setModel(goodsTableModel); goodsTable.addMouseListener(new MyMouseAdapter()); scrollPane.setViewportView(goodsTable); scrollPane.setBounds(0, 0, 240, 200); scrollPane.setSize(240,120); groundPanel.add(scrollPane); groundPanel.setPreferredSize(new Dimension(240, 200)); add(groundPanel); }
知道了,没有超过默认的出现滚动条行数。Dimension a=new Dimension();
a.height=80;
a.width=200;
goodsTable.setPreferredScrollableViewportSize(a);
给其他遇见类似问题的人一点帮助吧。
谁来领积分 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励20(财富值+成长值)
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询