Question

When I am running this, JLabel is not visible, but when I resize window (with mouse) JLabel is showed. Why?

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);

  }

}
Was it helpful?

Solution

This look like some of the L&F bugs in older Java VMs on newer OS. For example on Windows 7 the most problems are solved first with 1.6.0_17. You should start your program with a console. If you see some stacktraces in the event thread then it is a problem of an L&F bug.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top