【发布时间】:2018-08-31 20:19:34
【问题描述】:
我正在努力解决这个问题 2 个小时,但仍然没有真正发生任何事情。我尝试使用 revalidate、paintImmediately 等多种方法更新 JLabel,尽管它并没有改变最终结果。
public void notificationtos( ) { jLabel2.setText( "Read our ToS first, please." ); jLabel2.revalidate(); jLabel2.paintImmediately(jLabel2.getVisibleRect()); System.out.println("debug" ); System.out.println( jLabel2.getText() ); } private void jButton1MouseClicked(java.awt.event.MouseEvent evt) { if( prihvaceniuslovi == false ) { new notification().notificationtos(); new notification().setVisible(true); } }
同样是调试,下面是上面代码的输出:
run: debug Read our ToS first, please. BUILD SUCCESSFUL (total time: 3 seconds)
GUI 正常显示,但字符串与 JLabel 初始化时设置的字符串没有改变。
而不是照片中显示的下面的这个字符串... GUI Photo here
这个应该已经显示了
“请先阅读我们的服务条款。”
如果有人能真正帮助我,我将不胜感激。谢谢!
编辑,这是解决方案代码,非常感谢@camickr
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) { if( prihvaceniuslovi == false ) { notification objekt = new notification(); objekt.setVisible(true); objekt.notificationtos(); } }
【问题讨论】:
-
您是否在事件调度线程上调用
notificationtos( )?
标签: java swing jlabel gettext settext