Java – buttons are not initially drawn

There is a problem with my applet. The buttons won't be drawn until you hover over them They stay after that, but once you click on one, they disappear again This is my code:

checkPanel = new JPanel();

    buttonPanel = new JPanel();
    buttonPanel.setLayout( new GridLayout( 1,7 ) );

    openAdvancedSettings = new JButton( "Advanced Settings" );
    openAdvancedSettings.addActionListener( this );

    checkPanel = new JPanel();
    checkvolt = new Check@R_530_2419@( "Voltage",true );
    checkv = new Check@R_530_2419@( "v gate",false );
    checkw = new Check@R_530_2419@( "w gate",false );
    checks = new Check@R_530_2419@( "s gate",false );

    checkvolt.addItemListener( this );
    checkv.addItemListener( this );
    checkw.addItemListener( this );
    checks.addItemListener( this );

    checkPanel.setLayout( new GridLayout( 20,8 ) );
    checkPanel.add( butp );
    checkPanel.add( prompt0 );
    checkPanel.add( checkvolt );
    checkPanel.add( prompt1 );

    butt = new JButton( "Start" );
    butt.addActionListener( this );
    buttonPanel.add( butt );

    setLayout( new BorderLayout() );
    add( checkPanel,BorderLayout.EAST );
    add( buttonPanel,BorderLayout.NORTH );
    add( openAdvancedSettings,BorderLayout.soUTH );

The first two are jpanels and the last one is JButton Most buttons (except the last button) are in these two panels

I also concluded that the repaint () method caused this What on earth did I do wrong?

Solution

I assume that without a good sscce, you must not put your code in charge of creating and displaying your GUI to obtain concurrency in swing, in swingutilities invokelater(…);

I hope this may help to some extent to greet

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>