jtextarea 滚动条
如下部分代码,为什么添加滚动条后jtextarea和滚动条都不显示?(中间省略了一部分代码)publicclassFileEncrypterextendsJFrame{J...
如下部分代码,为什么添加滚动条后jtextarea和滚动条都不显示?(中间省略了一部分代码)
public class FileEncrypter extends JFrame{
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(false);
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); 展开
public class FileEncrypter extends JFrame{
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(false);
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); 展开
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();
}
}
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();
}
}
追问
谢谢帮忙。你那一段确实能显示,但是在我那个源程序里就不行了。
我是下的别人的程序,如果可以的话能再帮我看看完整的源程序吗?
代码复制过来就字数超限了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询