加了滚动条textArea不能用了,怎么改?

cctvnet 2003-06-23 08:32:42
加了滚动条textArea是灰色的55555555555555555555555555.......找不到错了
我的代码:
/**
* byq.java
* done by symbol windows风格
*/

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class byq extends JFrame
{
//定义
JButton Button1 = new JButton("开始编译"); //按钮
JTextArea textArea1 = new JTextArea ("在这里写代码",30,60);
JTextArea textArea2 = new JTextArea ("调试信息",30,60);
JLabel label1 = new JLabel("代码输入:"); //不是按钮,是静态文本
JLabel label2 = new JLabel("调试信息"); //不是按钮,是静态文本
//JScrollPane scrollPane1 = new JScrollPane(textArea1);
//JScrollPane scrollPane2 = new JScrollPane(textArea2);

public byq()
{
JScrollPane scrollPane1 = new JScrollPane(textArea1);//不写这里textArea不能用,写了还是不能用
JScrollPane scrollPane2 = new JScrollPane(textArea2);
//初始化
//getContentPane().setLayout(new java.awt.FlowLayout());//大小自动适合
getContentPane().setLayout( null );
textArea1.setLineWrap(true);
textArea2.setLineWrap(true);

getContentPane().add(textArea1);
getContentPane().add(textArea2);
getContentPane().add(Button1);

getContentPane().add(label1);
getContentPane().add(label2);
getContentPane().add(scrollPane1);
getContentPane().add(scrollPane2);
//颜色
getContentPane().setBackground(Color.GREEN);
label1.setForeground(Color.RED);
label2.setForeground(Color.RED);
Button1.setForeground(Color.red);

//方位大小
label1.setBounds(30,30,180,30);
label2.setBounds(30,300,180,30);
Button1.setBounds( 680, 600, 100,60 );
//textArea1.setBounds(30, 60, 700, 200);
//textArea2.setBounds(30, 330, 700, 200);
scrollPane1.setBounds(30, 60, 700, 200);
scrollPane2.setBounds(30, 330, 700, 200);


/* 为一般按钮添加动作监听器 */
Button1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
JOptionPane.showMessageDialog(null,"开始编译","标题",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
});
setSize(800, 700);
System.out.println("this is my first window");
}


public static void main(String[] args)
{
try
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch(Exception e)
{
e.printStackTrace();
}

byq win = new byq();
win.show();
}

}

...全文
199 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhjjava 2003-06-23
  • 打赏
  • 举报
回复
JScrollPane scrollPane1 = new JScrollPane(textArea1);
JScrollPane scrollPane2 = new JScrollPane(textArea2);
getContentPane().add(textArea1);
getContentPane().add(textArea2);
你把textArea即加在滚动面板里,又加在了contentPane中,所以会出错。去掉下面两句就行了。
正确,接粉!
XKP 2003-06-23
  • 打赏
  • 举报
回复
good
yuanmeng163 2003-06-23
  • 打赏
  • 举报
回复
你的错误是:
JScrollPane scrollPane1 = new JScrollPane(textArea1);
JScrollPane scrollPane2 = new JScrollPane(textArea2);
getContentPane().add(textArea1);
getContentPane().add(textArea2);
你把textArea即加在滚动面板里,又加在了contentPane中,所以会出错。去掉下面两句就行了。
XKP 2003-06-23
  • 打赏
  • 举报
回复
真是不好意思
我实在找不出你的程序里面那里错了
所以我就重新自己写过一遍

我有点怀疑是layout的问题
因为我主要也就是改layout的那个地方
不过我找不到问题在哪里
layout那样用好像也没有错

。。。。。。。。。。
cctvnet 2003-06-23
  • 打赏
  • 举报
回复
能说一下我的错误原因吗?
XKP 2003-06-23
  • 打赏
  • 举报
回复
这样就行了

/**
* byq.java
* done by symbol windows风格
*/

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class byq extends JFrame
{
//定义
JButton Button1 = new JButton("开始编译"); //按钮
JTextArea textArea1 = new JTextArea ("在这里写代码",30,60);
JTextArea textArea2 = new JTextArea ("调试信息",30,60);
JLabel label1 = new JLabel("代码输入:"); //不是按钮,是静态文本
JLabel label2 = new JLabel("调试信息"); //不是按钮,是静态文本
Container pane = getContentPane();
JScrollPane scrollPane1 = new JScrollPane(textArea1);
JScrollPane scrollPane2 = new JScrollPane(textArea2);

public byq() {
pane.setLayout( new BoxLayout( pane, BoxLayout.Y_AXIS ) );
textArea1.setLineWrap(true);
textArea2.setLineWrap(true);

pane.add(label1);
pane.add(scrollPane1);
pane.add(label2);
pane.add(scrollPane2);
pane.add(Button1);

//颜色
pane.setBackground( Color.GREEN );
label1.setForeground( Color.RED );
label2.setForeground( Color.RED );
Button1.setForeground( Color.RED );


/* 为一般按钮添加动作监听器 */
Button1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
JOptionPane.showMessageDialog(null,"开始编译","标题",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
});
setSize(800, 700);
System.out.println("this is my first window");
}


public static void main(String[] args)
{
try
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch(Exception e)
{
e.printStackTrace();
}

byq win = new byq();
win.setVisible( true );
}

}

62,635

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧