Orloffyeah Orloffyeah - 1 year ago 83
Java Question

Adding two JComponents to the North of a JFrame BorderLayout

I have a paint-like project, in which I recently added a JSpinner, but after researching how to add it to the JFrame, it ends up looking like this:

but I would like it to look like this:

how would I accomplish this? Thanks in advance.

P.D: The code used to create the current project is this:

public View( final String title ){
super( title );

public void init()
canvas = new Canvas();
menuManager = new MenuManager();
toolBarManager = new ToolBarManager( JToolBar.VERTICAL );
spinnerManager = new SpinnerManager();

JPanel subPanel = new JPanel( new FlowLayout() );

subPanel.add( menuManager );
subPanel.add( spinnerManager );

add( BorderLayout.CENTER, canvas );
add( BorderLayout.NORTH, menuManager);
add( BorderLayout.EAST, toolBarManager );

setDefaultCloseOperation( EXIT_ON_CLOSE );

App.getInstance().addDrawingListener( this );


Answer Source

Simply give the top JPanel an appropriate FlowLayout: new FlowLayout(FlowLayout.LEADING))

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download