日期:2014-05-20  浏览次数:20742 次

关于JLabel的setText在监听器中不刷新问题
我在事件监听中修改一个JLabel里的文字,但是原来的字体没有清除,后面的文字又叠加上去,如果不在监听中修改就正常,求助要怎么解决,是什么的原因?
------最佳解决方案--------------------
被遮盖的内容是什么?
那个没看清.
更改的JLabel1你setText("");
看原来的内容是否在。
另外下次上传代码的时候带上Java格式,
如下面的
java代码

最后,建议一下楼主多加注释
------其他解决方案--------------------
你用的是什么事件,事件里面是怎么写的。
关键部分的代码也要给出来啊
------其他解决方案--------------------
你应该把代码放出来大家才能帮你找到错误
------其他解决方案--------------------
对,把代码贴出来 大家共同看下
------其他解决方案--------------------
估计你实例化了两个JLabel对象。
还是发代码吧。要么谁也不能判断出错误原因。
------其他解决方案--------------------
xuexuexixi xuexi 
------其他解决方案--------------------
class test{
public static void main(String[] args)throws Exception{
MyFrame f = new MyFrame();
f.setSize(500,300);
f.setVisible(true);
}//main
}
         
class MyFrame extends JFrame {
public MyFrame()throws Exception{
   MainPanel mainPanel = new MainPanel();
   setLayout(new BorderLayout());
   add(mainPanel,"Center");
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}


class MainPanel extends JPanel{
// Declare a label for displaying message
private JLabel jLabel1 = new JLabel("Display the border type",JLabel.CENTER);

//A check box for seleting a border with or without a title
private JCheckBox jchkTitled;

// Radio buttons for border styles
private JRadioButton  jrbLoweredBevel , jrbRaisedBevel , jrbEtched , 
jrbLine , jrbMatte , jrbEmpty;

// Radio buttons for titled border options 
private JRadioButton  jrbAboveBottom , jrbBottom , jrbBelowBottom , jrbAboveTop ,
jrbTop , jrbBelowTop , jrbLeft , jrbCenter , jrbRight;

// TitledBorder for the label                  -------------------???????
private TitledBorder  jLabel1Border;

/** Constructor **/
public MainPanel(){
// Create a JLabel instance and set colors
jLabel1.setBackground(Color.red);
jLabel1.setBorder(jLabel1Border);

//11111111111111111111111111111111111
// Place title position radio buttons
JPanel jpPosition = new JPanel();
jpPosition.setLayout(new GridLayout(3,2));
jpPosition.add(jrbAboveBottom = new JRadioButton("ABOVE_BOTTOM"));
jpPosition.add(jrbAboveTop = new JRadioButton("ABOVE_TOP"));
jpPosition.add(jrbBottom = new JRadioButton("BOTTOM"));
jpPosition.add(jrbTop = new JRadioButton("TOP"));
jpPosition.add(jrbBelowBottom = new JRadioButton("BELOW_BOTTOM"));
jpPosition.add(jrbBelowTop = new JRadioButton("BELOW_TOP"));