gpt4 book ai didi

java - 滚动条不起作用

转载 作者:行者123 更新时间:2023-12-02 08:01:59 24 4
gpt4 key购买 nike

您好,这是我的滚动条的代码。不幸的是,它不起作用。怎么可能?

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);
}

最佳答案

设置 JScrollPane 的首选大小。

请勿不要设置JTextArea的首选大小。

来源:我稍微修改了源代码并且它起作用了。

关于java - 滚动条不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8777135/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com