java - How to assign the location of button? -


how can create button on frame in north , in center horizontally? (i.e not occupy width)?

borderlayout expands components in north location fill width of container. therefore need place in container respects preferred size of component, jbutton in case. can use default flowlayout in jpanel:

jpanel northpanel = new jpanel();  jbutton button = new jbutton("ok"); frame.add(northpanel, borderlayout.north); 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -