JTextAreaのフォントサイズを変更するためのJOptionPaneからの入力をユーザーに求めるようにしようとしています。JTextAreaのフォントサイズを変更する際の問題
問題:
私はサイズJMenuの項目をクリックしたときただし、JOptionPaneのは表示されません。
コード:私はサイズJMenuの項目をクリックしたときのJOptionPaneで
Font font = new Font("Arial", Font.PLAIN, 12);
panel = new JPanel();
panel.setLayout(new BorderLayout());
add(panel, BorderLayout.CENTER);
JTextArea console = new JTextArea();
console.setLineWrap(true);
console.setWrapStyleWord(true);
console.setEditable(false);
console.setFont(font);
JScrollPane scroll = new JScrollPane(console);
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
panel.add(scroll, BorderLayout.CENTER);
JMenuBar bar = new JMenuBar();
panel.add(bar, BorderLayout.NORTH);
JMenu size = new JMenu("Size");
size.addActionListener(new ActionListener() {
@Override public void actionPerformed(ActionEvent e) {
String fontSize = JOptionPane.showInputDialog(panel, "New font size, 6 or larger:", "Set Font Size", JOptionPane.OK_CANCEL_OPTION);
Font newFont = font.deriveFont(Integer.parseInt(fontSize));
console.setFont(newFont);
}
});
bar.add(size);
JtextareaのCant updateフォント。既に回答済みhttp://stackoverflow.com/questions/2488384/setting-fonts-in-a-jtextarea?rq=1 – VinuBibin
@VinuBibinしかし、問題を読んだら、クリックするとJOptionPaneが表示されないサイズJMenu項目 –
'JMenu'の代わりに' JMenuItem'を使用してください – copeg