jtextarea 滚动条

2025-02-02 23:51:42
推荐回答(1个)
回答1:

我运行后,能显示啊
public class FileEncrypter extends JFrame{

public FileEncrypter(){
JTextArea showProcess = new JTextArea();
showProcess.setBackground(SystemColor.control);

showProcess.setEnabled(true);

showProcess.setFont(new java.awt.Font("MonoSpaced", 0, 12));
showProcess.setForeground(new Color(104, 180, 50));
showProcess.setBorder(BorderFactory.createLoweredBevelBorder());
showProcess.setMinimumSize(new Dimension(0, 18));
showProcess.setPreferredSize(new Dimension(426,150));
showProcess.setCaretColor(Color.black);
showProcess.setEditable(true);
showProcess.setMargin(new Insets(0, 0, 0, 0));
showProcess.setSelectedTextColor(Color.white);
showProcess.setSelectionEnd(0);
showProcess.setText("加(解)密过程:");
showProcess.setLineWrap(true);//设置自动换行,自动换行则不会出现横向的滚动条
showProcess.setRows(3);
showProcess.setTabSize(8);
showProcess.setBounds(new Rectangle(21, 340, 426,150));//setBounds(int x, int y, int width, int height)
this.getContentPane().add(showProcess);

JScrollPane textPane = new JScrollPane(showProcess);
this.getContentPane().add(textPane);
textPane.setVerticalScrollBarPolicy (JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
JPanel jp = new JPanel();//添加一个面板
textPane.setPreferredSize(new Dimension(426,100));
jp.add(textPane);

this.getContentPane().add(jp);
this.setVisible(true);
this.pack();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public static void main(String[] args) {
// TODO Auto-generated method stub
new FileEncrypter();
}

}