请问JAVA怎么实现JTextArea的刷新,要能刷新字体的

import java.awt.Font;import java.awt.GraphicsEnvironment;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.ArrayList;import java.util.Random;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JScrollPane;import javax.swing.JTextArea;...
请问JAVA怎么实现JTextArea的刷新,要能刷新字体的
import java.awt.Container;import java.awt.Font;import java.awt.GraphicsEnvironment;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.ArrayList;import java.util.Random;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JScrollPane;import javax.swing.JTextArea;public class JtextAreaDemo extends JFrame implements ActionListener { private JScrollPane pane = new JScrollPane(); private JTextArea area = new JTextArea(); private JButton button = new JButton("Click Me"); private ArrayList<String> list = new ArrayList<String>(); public JtextAreaDemo() { super("Change JTextArea Font"); try { init(); } catch (Exception e) { e.printStackTrace(); } } private void init() { pane.getViewport().add(area); pane.setAutoscrolls(true); pane.setWheelScrollingEnabled(true); pane.setBounds(10, 10, 580, 280); button.setBounds(240, 300, 100, 25); button.addActionListener(this); Container c = this.getContentPane(); c.setLayout(null); c.add(pane); c.add(button); String[] fontNames = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); for (String fontName : fontNames) { list.add(fontName); } this.setSize(600, 400); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setResizable(false); this.setLocationRelativeTo(null); this.setVisible(true); } public static void main(String[] args) { new JtextAreaDemo(); } public void actionPerformed(ActionEvent e) { if (e.getSource() == button) { Random random = new Random(); int size = random.nextInt(150) + 5; String name = list.get(random.nextInt(list.size())); area.setFont(new Font(name, 0, size)); } }}

2013-06-02
设置JTextArea的字体直接用setFont方法就可以2013-06-02
mengvlog 阅读 31 次 更新于 2025-09-09 18:33:43 我来答关注问题0
  •  田拔0U 用JAVA编个简单的记事本程序

    文件= new JMenu("文件"); 编辑= new JMenu("编辑"); 新建= new JMenuItem("新建"); 打开= new JMenuItem("打开"); 保存= new JMenuItem("保存"); 另存为 = new JMenuItem("另存为"); 退出= new JMenuItem("退出"); 查找= new JMenuItem("查找"); 文件.add(新建); 文件.add(打开)...

  • 在Java中,设置字体颜色主要通过Swing或JavaFX等图形用户界面库来实现。对于Swing应用,可以通过设置JLabel、JTextField等组件的默认属性来更改字体颜色。例如:1. 对于JLabel组件,可以使用setForeground(Color)方法来设置字体颜色。例如,设置字体为红色,可以这样做:java JLabel label = new JLabel("Hello,...

  •  猪八戒网 Java中怎么设置JLabel的字体样式,大小,颜色

    1、打开Myeclipse的相关界面,在Window那里点击Preferences。2、弹出设置的对话框,选择General下的Appearance进入。3、点击ColorsandFonts按钮,需要在右侧选择Java。4、选择JavaEditorTextFont,并点击Edit。5、通过设置对应的参数以后,直接确定返回。6、这样一来会看到图示的结果,即可设置JLabel的字体样式,大...

  •  誉祥祥知识 JAVA里 getText()  是什么意思,怎么用

    当你需要从用户界面控件中提取文本内容时,可以使用getText方法。适用于各种控件,如JLabel、JButton、JTextField等。示例:创建一个JLabel对象并设置文本内容:javaJLabel status = new JLabel; 通过调用getText方法获取JLabel对象的文本内容:javaString text = status.getText;// 此时,text变量的值为"选...

  • public class JtextAreaDemo extends JFrame implements ActionListener { private JScrollPane pane = new JScrollPane(); private JTextArea area = new JTextArea(); private JButton button = new JButton("Click Me"); private ArrayList list = new ArrayList(); pu...

檬味博客在线解答立即免费咨询

Java相关话题

Copyright © 2023 WWW.MENGVLOG.COM - 檬味博客
返回顶部