java中设置了背景颜色,为什么不能显示?
来源:百度知道 编辑:UC知道 时间:2024/05/24 03:13:11
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);
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);
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(&qu