JTextPane的初始大小 如何设置
来源:百度知道 编辑:UC知道 时间:2024/06/23 12:01:41
二楼错了
JTextPane不支持setPreferredSize(100, 200)
可以改为
jep.setPreferredSize(new Dimension(100,200));
即可
jep.setPreferredSize(100, 200);
对二楼说得对
JTextPane的例子,模拟聊天客户端,演示了为每段文字设置字体、字号、样式、颜色、背景色和插入图片功能
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.UIManager;
import javax.swing.text.BadLocationException;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing