[好,所以我正在制作一个简单的程序,根据单击相应的按钮,将编辑JTextPane的能力设置为true或false。但是,我不知道如何禁用和重新启用编辑-窗格的功能。 JTextPane这是我苦苦挣扎的代码:
`JTextPane Pad1 = new JTextPane();
Pad1.setText("Edit Me...");
Pad1.setBounds(10, 45, 188, 160);
frmDuvalStudiosOffscreen.getContentPane().add(Pad1);
JButton button = new JButton("Save");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
//I want to make it when this button is clicked, it sets the ability to edit Pad1 to false.
}
});
button.setBounds(10, 239, 89, 23);
frmDuvalStudiosOffscreen.getContentPane().add(button);
JButton button_1 = new JButton("Edit");
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
//I want to make it when this button is clicked, it sets the ability to edit Pad1 to true.
}
});'
请提供代码和文字。谢谢!
有两种方法:
设置指定的布尔值以指示此TextComponent是否应可编辑。
setEditable(boolean b)
:设置是否启用此组件。启用的组件可能响应用户输入,而未启用的组件不能响应用户输入