0

So i have been doing gui for my program. But there is problem with positioning things on borderlayout.

enter image description here

There is positioning that i want them to be. Using BorderLayout. But this is where they currently are

enter image description here

So i want spinner between right and left combobox, but under textarea and button. Like on picture i mentioned before. I have no idea what to do.

DavidPostill
  • 7,734
  • 9
  • 41
  • 60
  • 1
    Welcome to Stack Overflow, please take the [Tour](http://stackoverflow.com/tour). Post your code, see [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – DavidPostill Aug 17 '14 at 15:33
  • Why don't you add the text area and the spinner to a panel, then add that panel to the center. That's legal. Also maybe you just want to use a text _field_ and not a text _area_. Just a suggestion. – Paul Samsotha Aug 17 '14 at 15:39
  • One way to layout a complex GUI is to use [combinations of layout managers](http://stackoverflow.com/a/5630271/418556) as well as [layout padding and borders](http://stackoverflow.com/q/17874717/418556) for white space. – Andrew Thompson Aug 18 '14 at 04:44

2 Answers2

0

Just use a combination of layout managers in a tree-like manner, i.e., container with a specific layout inside other containers with (possible) other layouts. For example, this might be a snippet for your app:

JPanel innerPanel = new JPanel( new BorderLayout() );
innerPanel.add( textArea, BorderLayout.CENTER );
innerPanel.add( spinner, BorderLayout.SOUTH );

JPanel outerPanel = new JPanel( new BorderLayout() );
outerPanel.add( calcButton, BorderLayout.NORTH );
outerPanel.add( panzerCombo, BorderLayout.WEST );
outerPanel.add( widthCombo, BorderLayout.EAST );
outerPanel.add( innerPanel , BorderLayout.CENTER );
Extremely
  • 470
  • 4
  • 10
-2

For this situation I find it easier not to use BorderLayout but to use absolute positioning because you can put a inifite amount of components where ever you want inside of the JFrame.

Link for reference: http://docs.oracle.com/javase/tutorial/uiswing/layout/none.html

  • 2
    A null layout is almost always a bad idea. It will look poor on other computers (where different fonts are in use) and won't resize correctly. Any future change to a JComboBox's items may result in clipping. See also http://stackoverflow.com/questions/6592468/why-is-it-frowned-upon-to-use-a-null-layout-in-swing . – VGR Aug 17 '14 at 16:09