java中设置了背景颜色,为什么不能显示?
importjava.awt.*;importjavax.swing.*;publicclassTransAndChatextendsJFrame{privateJLab...
import java.awt.*;
import javax.swing.*;
public class TransAndChat extends JFrame
{
private JLabel jla=new JLabel("用户名");;
private JLabel jlb=new JLabel("主机名");
private JLabel jlc=new JLabel("IP地址");;
JPanel jpList;
JScrollPane jsp=new JScrollPane(jpList);
public TransAndChat()
{
//界面
this.setLayout(null);
jla.setBounds(30,20,40,40);
this.add(jla);
jlb.setBounds(90,20,40,40);
this.add(jlb);
jlc.setBounds(150,20,40,40);
this.add(jlc);
JPanel jpList=new JPanel();
jsp.setBounds(5,20,280,150);
jpList.setBackground(Color.blue);
this.add(jsp);
this.setTitle("Java局域网文件传输器");
this.setBounds(100,100,300,400);
this.setBackground(Color.blue);
this.setVisible(true);
}
public static void main(String[] args)
{
new TransAndChat();
}
} 展开
import javax.swing.*;
public class TransAndChat extends JFrame
{
private JLabel jla=new JLabel("用户名");;
private JLabel jlb=new JLabel("主机名");
private JLabel jlc=new JLabel("IP地址");;
JPanel jpList;
JScrollPane jsp=new JScrollPane(jpList);
public TransAndChat()
{
//界面
this.setLayout(null);
jla.setBounds(30,20,40,40);
this.add(jla);
jlb.setBounds(90,20,40,40);
this.add(jlb);
jlc.setBounds(150,20,40,40);
this.add(jlc);
JPanel jpList=new JPanel();
jsp.setBounds(5,20,280,150);
jpList.setBackground(Color.blue);
this.add(jsp);
this.setTitle("Java局域网文件传输器");
this.setBounds(100,100,300,400);
this.setBackground(Color.blue);
this.setVisible(true);
}
public static void main(String[] args)
{
new TransAndChat();
}
} 展开
4个回答
展开全部
private JLabel jla=new JLabel("用户名");;
private JLabel jlb=new JLabel("主机名");
private JLabel jlc=new JLabel("IP地址");;
不要ADD到this而是ADD到jpList
如:
import java.awt.*;
import javax.swing.*;
public class T extends JFrame
{
private JLabel jla=new JLabel("用户名");;
private JLabel jlb=new JLabel("主机名");
private JLabel jlc=new JLabel("IP地址");;
JPanel jpList;
JScrollPane jsp;
public T()
{
//界面
JPanel jpList=new JPanel();
jpList.setBackground(Color.blue);
this.setLayout(null);
jla.setBounds(30,20,40,40);
jpList.add(jla);
jlb.setBounds(90,20,40,40);
jpList.add(jlb);
jlc.setBounds(150,20,40,40);
jpList.add(jlc);
jsp=new JScrollPane(jpList);
jsp.setBounds(5,20,280,150);
this.add(jsp);
this.setTitle("Java局域网文件传输器");
this.setBounds(100,100,300,400);
this.setBackground(Color.blue);
this.setVisible(true);
}
public static void main(String[] args)
{
new T();
}
}
private JLabel jlb=new JLabel("主机名");
private JLabel jlc=new JLabel("IP地址");;
不要ADD到this而是ADD到jpList
如:
import java.awt.*;
import javax.swing.*;
public class T extends JFrame
{
private JLabel jla=new JLabel("用户名");;
private JLabel jlb=new JLabel("主机名");
private JLabel jlc=new JLabel("IP地址");;
JPanel jpList;
JScrollPane jsp;
public T()
{
//界面
JPanel jpList=new JPanel();
jpList.setBackground(Color.blue);
this.setLayout(null);
jla.setBounds(30,20,40,40);
jpList.add(jla);
jlb.setBounds(90,20,40,40);
jpList.add(jlb);
jlc.setBounds(150,20,40,40);
jpList.add(jlc);
jsp=new JScrollPane(jpList);
jsp.setBounds(5,20,280,150);
this.add(jsp);
this.setTitle("Java局域网文件传输器");
this.setBounds(100,100,300,400);
this.setBackground(Color.blue);
this.setVisible(true);
}
public static void main(String[] args)
{
new T();
}
}
展开全部
现在可以了
import java.awt.*;
import javax.swing.*;
public class TransAndChat extends JFrame
{
private JLabel jla=new JLabel("用户名");;
private JLabel jlb=new JLabel("主机名");
private JLabel jlc=new JLabel("IP地址");;
public Test5()
{
//界面
jla.setBounds(30,20,40,40);
this.add(jla);
jlb.setBounds(90,20,40,40);
this.add(jlb);
jlc.setBounds(150,20,40,40);
this.add(jlc);
JPanel jp=new JPanel();
jp.setBounds(5,20,280,150);
jp.setBackground(Color.blue);
this.add(jp);
this.setTitle("Java局域网文件传输器");
this.setBounds(100,100,300,400);
this.setBackground(Color.blue);
this.setVisible(true);
this.setLayout(null);
}
public static void main(String[] args)
{
new TransAndChat ();
}
}
import java.awt.*;
import javax.swing.*;
public class TransAndChat extends JFrame
{
private JLabel jla=new JLabel("用户名");;
private JLabel jlb=new JLabel("主机名");
private JLabel jlc=new JLabel("IP地址");;
public Test5()
{
//界面
jla.setBounds(30,20,40,40);
this.add(jla);
jlb.setBounds(90,20,40,40);
this.add(jlb);
jlc.setBounds(150,20,40,40);
this.add(jlc);
JPanel jp=new JPanel();
jp.setBounds(5,20,280,150);
jp.setBackground(Color.blue);
this.add(jp);
this.setTitle("Java局域网文件传输器");
this.setBounds(100,100,300,400);
this.setBackground(Color.blue);
this.setVisible(true);
this.setLayout(null);
}
public static void main(String[] args)
{
new TransAndChat ();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
第一,前面那个JPanel jpList; 要去掉,你在后面重新定义了一次~~
第二,……
第二,……
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
this.setBackground(Color.blue)完全是多余的,你设置的是面板里的jpList.setBackground(Color.blue); 而且JPanel jp=new JPanel()定义的2次
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询