JFrame下面加带滚动条的JTextArea无法显示?

今天 写程序 遇到一个问题,就是直接在JFrame下面加带滚动条的JTextArea,无法  显示出来(不带 滚动条的我没试过不太清楚)

 

结果原因是没有加上JPanel

 

先将JTextArea加上滚动条, 

 再将滚动条到JP anel上面,

最后将JPanel加到JFame,

完成! 

可以 显示!

        super("֪知识补全");
		this.setBounds(70,70,1300,650);
		this.setLayout(null);
		jp = new JPanel();
		jp.setBounds(5,60,1120,500);
		jp.setLayout(new GridLayout());
        
//�����ı���
		jta = new JTextArea[4];
		jta[0] = new JTextArea();
		jta[1] = new JTextArea();
		jta[2] = new JTextArea("");

		//设置文本域的位置
//		jta[0].setBounds(0,60,560,590);
//		jta[1].setBounds(565,60,560,590);
		
		//设置自动换行
		jta[0].setLineWrap(true);
		jta[1].setLineWrap(true);
		jta[2].setLineWrap(true);
		
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
1.(25分)参考程序: import java.awt.*; import javax.swing.*; import java.util.*; public class Test1 extends JFrame { JTextArea text; public Test1(String s) { super(s); Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout( )); text=new JTextArea(10,20); // String str[]=new String[5]; String s1="排序前:\n"; for(int i=0;i<str.length;i++){ str[i]=JOptionPane.showInputDialog("请输入字符串"); s1+=str[i]+"\t"; } text.setText(s1); Arrays.sort(str); String s2="\n排序后:\n"; for(int i=0;i<str.length;i++){ s2+=str[i]+"\t"; } text.append(s2); // contentPane.add(text,BorderLayout.CENTER); setSize(400,160); setVisible(true); } public static void main (String[] args) { Test1 w=new Test1("第一题"); } } 2、(25分)参考程序: import java.io.*; public class Test2 { public static void main(String args[])throws IOException{ File file1=new File("d:\\xxx\\yyy\\zzz"); file1.mkdirs(); File file2=new File(file1,"1.txt"); file2.createNewFile(); String s="I like java."; byte[] b=s.getBytes(); FileOutputStream out=new FileOutputStream(file2); out.write(b); for(char ch='a';ch<='z';ch++){ out.write(ch); } out.close(); /////////////////////////// FileInputStream readfile=new FileInputStream(file2); int b1; while((b1=readfile.read())!=-1){ System.out.print((char)b1); } readfile.close(); } } 3、(25分)参考程序: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Test3 extends JFrame { JTextArea text;//文本区 JButton btn[]=new JButton[3]; public Test3(String str){ super(str); Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); text=new JTextArea(20,20); text.setFont(new Font("楷体_gb2312",Font.PLAIN,30)); contentPane.add(text,BorderLayout.CENTER);//将文本区添到窗口中间 JPanel panel=new JPanel();//创建缺省布局方式(FlowLayout)的面板 for(int i=0;i<btn.length;i++){//初始化5个按钮并添到面板中 btn[i]=new JButton("按钮"+(i+1));//循环创建5个按钮 panel.add(btn[i]);//将按钮添到面板中 } // btn[0].addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { text.append("java程序设计\n"); } }); btn[1].addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { Color cr=JColorChooser.showDialog(null,"调色板",Color.red); text.setForeground(cr); } }); btn[2].addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { Color cr=JColorChooser.showDialog(null,"调色板",Color.red); text.setBackground(cr); } }); // contentPane.add(panel,BorderLayout.NORTH);//将面板添到窗口北边 setSize(400,300); setVisible(true); } public static void main(String args[]){ new Test3("第3题"); } }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值