精華區beta TTU-I90B 關於我們 聯絡資訊
馬的 =.=| Swing的scrolling超基掰.. 終於搞定orz 下面是程式碼! 有加上SpringLayout --> 類似SWT的FormLayout Panel要先把TextArea丟進JScrollPane在add到上一層的Pane JTextArea textArea = new JTextArea(); textArea.setEditable(false); textArea.setDoubleBuffered(true); textArea.setBorder(new TitledBorder(null, "", TitledBorder.DEFAULT_JUSTIFICA TION, TitledBorder.DEFAULT_POSITION, null, null)); springLayout.putConstraint(SpringLayout.SOUTH, textArea, -5, SpringLayout.SO UTH, panel); springLayout.putConstraint(SpringLayout.EAST, textArea, -5, SpringLayout.EAS T, panel); springLayout.putConstraint(SpringLayout.NORTH, textArea, 5, SpringLayout.SOU TH, startButton); springLayout.putConstraint(SpringLayout.WEST, textArea, 0, SpringLayout.WEST , startButton); JScrollPane scrollPane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); scrollPane.setAutoscrolls(true); scrollPane.setViewportView(textArea); panel.add(scrollPane); springLayout.putConstraint(SpringLayout.SOUTH, scrollPane, -5, SpringLayout. SOUTH, panel); springLayout.putConstraint(SpringLayout.NORTH, scrollPane, 0, SpringLayout.S OUTH, startButton); springLayout.putConstraint(SpringLayout.EAST, scrollPane, -5, SpringLayout.E AST, panel); springLayout.putConstraint(SpringLayout.WEST, scrollPane, 5, SpringLayout.WE ST, panel);