2

I would like to ask if SpringLayout can do anything like absolute position because I think absolute position have problem when I maximize the frame and what do I have to use if I need to set JMenu and JToolBar and JTextField and JTable all in one line in order?

I tried to use Borderlayout but it give me very big JTextField. I tried Gridlayout it give also big JTextField I need it big but not as big as it shows up.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
isslam akkilah
  • 418
  • 1
  • 11
  • 23

3 Answers3

4

can SpringLayout do all the job

No. It is neither designed, nor intended to do 'all the job'.

Java GUIs might have to work on a number of platforms, on different screen resolutions & using different PLAFs. As such they are not conducive to exact placement of components. To organize the components for a robust GUI, instead use layout managers, or combinations of them1, along with layout padding & borders for white space2.

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
2

For absolute positioning, don't use a layout manager at all.

However, that's not really recommended. Usually you should use a layout that would scale.

See also this thread for more discussion.

Community
  • 1
  • 1
eis
  • 51,991
  • 13
  • 150
  • 199
0

i found note writing by java says

Note: This lesson covers writing layout code by hand, which can be challenging. If you are not interested in learning all the details of layout management, you might prefer to use the GroupLayout layout manager combined with a builder tool to lay out your GUI. One such builder tool is the NetBeans IDE. Otherwise, if you want to code by hand and do not want to use GroupLayout, then GridBagLayout is recommended as the next most flexible and powerful layout manager

isslam akkilah
  • 418
  • 1
  • 11
  • 23
  • I was almost going to mention `GroupLayout` but refrained since the experts tend to feel it is *only* usable with an IDE. If you are allowed to use an IDE, it might be a good choice. The advice re. `GridBagLayout` is also pretty true. I know people that swear by it. Unfortunately I've never managed to wrap my head around using it properly. – Andrew Thompson Jan 01 '14 at 20:05
  • if you are not so good at GridBagLayout so what you are using for layout – isslam akkilah Jan 01 '14 at 20:19
  • 1
    *"what you are useing for layout"* That really seems like a silly question given I linked to not one, but **two, *code examples*** that tell you exactly that. Did you follow the links, or do you expect me to spoon-feed the information to you? In fact, look at 1st the freaking *picture.* It includes titled borders that explicitly state the layouts. – Andrew Thompson Jan 01 '14 at 20:21
  • 1
    I'm one of those people who swears by GridBagLayout, though I find almost every nontrivial UI ends up needing a combination of layouts. The note you have quoted is correct: If you're going to code by hand, you need to learn GridBagLayout. GridBagLayout is difficult to learn, but I recall one person wisely describing it as "irreducible complexity," which I agree with fully. GridBagLayout is difficult to learn because layout itself is difficult. Everything GridBagLayout addresses is a consideration you cannot ignore if you want your layout to behave properly—especially weight, fill, and anchor. – VGR Jan 01 '14 at 20:34