在 JOptionPane 中更改 JTextArea 的字体
Changing font of JTextArea in JOptionPane
我只是想知道您是否可以通过使用 area.getText()
以某种方式更改 showMesaggesDialog
中的文本字体(区域是我对 JTextArea
的要求)到目前为止我已经试过了,但没有成功。
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String myString=area.getText();
Font font = new Font("Verdana", Font.BOLD, 12);
area.setFont(font);
JOptionPane.showMessageDialog(f.getComponent(0),myString);
}
});
不要使用字符串调用 JOptionPane.showMessageDialog,而是使用 JLabel。
试试这个:
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String myString=area.getText();
JLabel label = new JLabel(myString);
Font font = new Font("Verdana", Font.BOLD, 12);
label.setFont(font);
JOptionPane.showMessageDialog(f.getComponent(0),label);
}
});
我只是想知道您是否可以通过使用 area.getText()
以某种方式更改 showMesaggesDialog
中的文本字体(区域是我对 JTextArea
的要求)到目前为止我已经试过了,但没有成功。
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String myString=area.getText();
Font font = new Font("Verdana", Font.BOLD, 12);
area.setFont(font);
JOptionPane.showMessageDialog(f.getComponent(0),myString);
}
});
不要使用字符串调用 JOptionPane.showMessageDialog,而是使用 JLabel。
试试这个:
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String myString=area.getText();
JLabel label = new JLabel(myString);
Font font = new Font("Verdana", Font.BOLD, 12);
label.setFont(font);
JOptionPane.showMessageDialog(f.getComponent(0),label);
}
});