我正在构建一个充满标签的网格。其中一个包含html文本,并应调整为最大格式并可滚动。我发现如何添加一个JScrollPane,但它保持一行高度,即使当我给它一个400x400的大小时,我也找不到如何调整它的大小......将一个可滚动的jpanel添加到网格布局
删除getViewport()会得到相同的结果。
JPanel grid = new JPanel(new GridLayout(1,2));
// first cell of the grid
grid.add(new JLabel("title"));
// second cell of the grid, this should be the scrollable one
JScrollPane scroll = new JScrollPane();
scroll.getViewport().setSize(400, 400);
scroll.getViewport().add(new JLabel("<html>long<br>html<br>text</html>"));
grid.add(scrollVersion, BorderLayout.CENTER);
任何想法?
非常感谢......
我想你试过'setMinimumSize'? – sje397 2010-07-19 10:06:23