下面代码中.我直接用setBackground(Color.red);设置背景颜色根本没用,但是
//Container conPane=getContentPane();
//conPane.setBackground(Color.red);
然后再用 conPane.setBackground(Color.red);中间的那层没有颜色,这是为什么?
还有,如何能让l=new JLabel("移动滚动条可改变背景颜色");
这一句居中显示?
import java.awt.*;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;import javax.swing.*;
public class Src extends JFrame {
JTextField text;
s S;
JLabel l;
Src()
{
//Container conPane=getContentPane();
//conPane.setBackground(Color.red);
l=new JLabel("移动滚动条可改变背景颜色");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBackground(Color.red);
setSize(500,250);
setVisible(true);
setLayout(new GridLayout(3,1,1500,0));
S=new s();
setBackground(Color.red);
add(l);
add(S);
}
public static void main(String[] args)
{
new Src();
}
class s extends JPanel implements AdjustmentListener
{ JTextField t;
JScrollBar bar;
JScrollBar bar1;
JScrollBar bar2;
s()
{
bar=new JScrollBar(JScrollBar.HORIZONTAL,0,0,0,255);
bar1=new JScrollBar(JScrollBar.HORIZONTAL,0,0,0,255);
bar2=new JScrollBar(JScrollBar.HORIZONTAL,0,0,0,255);
setLayout(new FlowLayout());
bar.setPreferredSize(new Dimension(100,20));
bar1.setPreferredSize(new Dimension(100,20));
bar2.setPreferredSize(new Dimension(100,20));
add(bar);
add(bar1);
add(bar2);
bar.addAdjustmentListener(this);
bar1.addAdjustmentListener(this);
bar2.addAdjustmentListener(this);
}
public void adjustmentValueChanged(AdjustmentEvent e) {
}
}}
//Container conPane=getContentPane();
//conPane.setBackground(Color.red);
然后再用 conPane.setBackground(Color.red);中间的那层没有颜色,这是为什么?
还有,如何能让l=new JLabel("移动滚动条可改变背景颜色");
这一句居中显示?
import java.awt.*;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;import javax.swing.*;
public class Src extends JFrame {
JTextField text;
s S;
JLabel l;
Src()
{
//Container conPane=getContentPane();
//conPane.setBackground(Color.red);
l=new JLabel("移动滚动条可改变背景颜色");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBackground(Color.red);
setSize(500,250);
setVisible(true);
setLayout(new GridLayout(3,1,1500,0));
S=new s();
setBackground(Color.red);
add(l);
add(S);
}
public static void main(String[] args)
{
new Src();
}
class s extends JPanel implements AdjustmentListener
{ JTextField t;
JScrollBar bar;
JScrollBar bar1;
JScrollBar bar2;
s()
{
bar=new JScrollBar(JScrollBar.HORIZONTAL,0,0,0,255);
bar1=new JScrollBar(JScrollBar.HORIZONTAL,0,0,0,255);
bar2=new JScrollBar(JScrollBar.HORIZONTAL,0,0,0,255);
setLayout(new FlowLayout());
bar.setPreferredSize(new Dimension(100,20));
bar1.setPreferredSize(new Dimension(100,20));
bar2.setPreferredSize(new Dimension(100,20));
add(bar);
add(bar1);
add(bar2);
bar.addAdjustmentListener(this);
bar1.addAdjustmentListener(this);
bar2.addAdjustmentListener(this);
}
public void adjustmentValueChanged(AdjustmentEvent e) {
}
}}
解决方案 »
- Hdu 1009 求助求助 ,找不到错误郁闷啊
- swing写的桌面程序,可不可以设置两个表格同步滚动啊?
- 一个简单的java题,你能做出来吗?
- 用exe4j生成的可执行程序怎么在没有jre的机器上运行?
- 如何配置java運行環境
- java应用程序怎么关闭打开的网页哦
- 怎样获取系统的前进,后退的箭头图标
- thining in java的一道题
- 简单问题:错误提示(java.sql.SQLException:Column not found)!!!
- 数组进行冒泡排序后 里面的元素再输出的时候全都变成0了
- 图像为什么会显示不出来...
- 求助!Java连数据库问题~~~~~~~~~~~~~~~~~~~~~~~~
对于Jframe设置背景色直接setBackground(Color.red);是不行的,不知道你怎么写那么多遍...应该是:getContentPane().setBackground(Color.red);
getContentPane().setBackground(Color.red);