java jtextarea滚动条_如何在Swing中向JTextArea添加垂直滚动条?

我有这个Gui课程:

public class Gui extends JFrame implements ActionListener {

/**

*

*/

private static final long serialVersionUID = -384241835772507459L;

JLabel playerInfo;

JTextField textField;

private final static String newline = "\n";

JTextArea feed;

JScrollPane scrollPane;

Player player;

public Gui() {

super("Erik's RPG");

setLayout(new FlowLayout());

textField = new JTextField(30);

textField.addActionListener(this);

feed = new JTextArea(15, 30);

feed.setEditable(false);

}

public void setCurrentPlayer(Player currentPlayer) {

player = currentPlayer;

playerInfo = new JLabel("Health = " + currentPlayer.getHealth() + " | Mana = " + player.getMana());

playerInfo.setBorder(BorderFactory.createTitledBorder(currentPlayer.getName()));

add(playerInfo);

add(feed);

add(textField);

}

当一堆文本在文本字段中时,它很烦人,因为它会使窗口变大.我需要知道如何制作滚动条,以便用户不必继续调整其JFrame的大小.另外,如何锁定JFrame的尺寸以便用户可以调整尺寸?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值