Something seems wrong with the layout, JButton showing unexpected behaviour at resize of the window

前端 未结 4 713
别那么骄傲
别那么骄傲 2020-11-22 02:32

JRE Version 1.7 Update 3

EXPECTED BEHAVIOUR

As I run the program, it works as expected, everything works smoothly. As when

4条回答
  •  你的背包
    2020-11-22 03:03

    I am unsure whether I found a solution for your system, but adjusting the code to

    colourButton = new JButton( "BALL COLOUR" );
    colourButton.setOpaque( true );
    colourButton.setBackground( colours[ colourCounter ] );
    colourButton.setForeground( Color.WHITE );
    

    works on my system (OS X with Java 1.7). Note the setOpaque call, which is needed so that the setBackground call has any effect as stated in the javadoc of that method:

    Sets the background color of this component. The background color is used only if the component is opaque

    On OS X, without that setOpaque call your code does not even work before a resize

提交回复
热议问题