문제

이것을 실행하면 JLabel이 표시되지 않지만 마우스로 창 크기를 조정하면 JLabel이 표시됩니다.왜?

import javax.swing.*;
import java.awt.*;

public class FrmTaoLogin extends JFrame {

  private JPanel pnlLeft = new JPanel();

  public FrmTaoLogin() {

    super();

    pnlLeft.setBorder(BorderFactory.createEtchedBorder());
    pnlLeft.add(new JLabel("test1"));
    getContentPane().add(pnlLeft,BorderLayout.SOUTH);

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(200, 200); 

  }

  public static void main(String[] args) {

    FrmTaoLogin FrmLogin = new FrmTaoLogin();
    FrmLogin.setVisible(true);

  }

}
도움이 되었습니까?

해결책

이는 최신 OS의 이전 Java VM에 있는 일부 L&F 버그처럼 보입니다.예를 들어 Windows 7에서는 대부분의 문제가 1.6.0_17에서 먼저 해결됩니다.콘솔로 프로그램을 시작해야 합니다.이벤트 스레드에 일부 스택 추적이 표시되면 L&F 버그 문제입니다.

다른 팁

IIRC, this happens when you don't call Frame.pack(). It should work if you call 'pack()' as the last line of the constructor.

I suspect that the problem here may have to do with trying to build and show your GUI components outside of the Swing thread.

What if you change main() to invoke your GUI code on the Swing thread, like this?

public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            FrmTaoLogin FrmLogin = new FrmTaoLogin();
            FrmLogin.setVisible(true);
        }
    });
}

Thanx to all, problem resolved. I change Windows theme and all working fine. I think that's Windows Aero and my NVIDIA GeForce FX5500 problem. This card official not working with windows Aero.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top