我正在構建一個充滿標籤的網格。其中一個包含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