嗨,這裏是我滾動條的代碼。不幸的是它不起作用。怎麼會這樣?滾動條不起作用
text_area = new JTextArea();
text_area.setPreferredSize(new Dimension(250,150));
text_area.setLineWrap(true);
scrollpane = new JScrollPane(text_area);
當我插入一個文本,它比滾動條不出現的區域更長。
這裏是代碼:
public AziendaGUI() {
company = new Azienda();
frame = new JFrame("Immobiliari s.p.a");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
view_list = new JButton("View Property");
view_list.setActionCommand("view_list");
view_list.addActionListener(this);
save_list = new JButton("Save List");
save_list.setActionCommand("save_list");
save_list.addActionListener(this);
text_area = new JTextArea();
text_area.setPreferredSize(new Dimension(250,150));
text_area.setLineWrap(true);
scrollpane = new JScrollPane(text_area); //Non funziona la scroll bar
grid = new GridBagLayout();
pane = new JPanel(grid);
/* Set Constraints view_list button */
grid.setConstraints(view_list, new GridBagConstraints(0,0,1,1,0.0,0.0,GridBagConstraints.WEST,GridBagConstraints.NONE,new Insets(5,5,5,5),0,0));
pane.add(view_list);
/* Set Constraints save_list button */
grid.setConstraints(save_list,new GridBagConstraints(1,0,1,1,0.0,0.0,GridBagConstraints.EAST,GridBagConstraints.NONE,new Insets(5,5,5,5),0,0));
pane.add(save_list);
/* Set Constraint text area */
grid.setConstraints(scrollpane, new GridBagConstraints(0,1,2,1,0.0,0.0,GridBagConstraints.CENTER,GridBagConstraints.NONE,new Insets(5,5,5,5),0,0));
pane.add(scrollpane);
frame.setLayout(new FlowLayout());
frame.add(pane);
frame.pack();
frame.setVisible(true);
}
顯示在哪裏添加了'JComponent'(s)可能有幫助。 – 2012-01-08 11:35:51
我發佈了整個代碼。 – Mazzy 2012-01-08 11:38:10