1

https://i.stack.imgur.com/wtxDr.png

I'm very new to Java Swing and Java overall (my class just got finished on Scanner and basics). I was taught only Swing basics which is "What is a JFrame..etc" and I'm stuck on how to layout or position things. On the image is the layout I desired and could anyone help and teach me how to code it? JFrame with, 5 JPanel components?(4 columns and the order form below)

Additionally, when clicking the "CONFIRM" button, I would want a new window to popup. How would I be able to link multiple windows?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
samo
  • 23
  • 2
  • 1
    1) *"Additionally,.."* Additional questions are best asked on additional Q&A threads. This helps people find answers later. 2) Start from the 'inside out'. Identify a layout that can work for a small section. Put those components in a panel that is then positioned in another layout in another panel. 3) I would say that a `GridBagLayout` would work well for the title / author / code / price section, but a `JTable` would probably be better. 4) Consider using a `TitledBorder` instead of the title at the top. 5) Show some effort towards achieving the goal. SO is not a help-desk. – Andrew Thompson Apr 03 '19 at 03:02

1 Answers1

2

A common strategy to solve complex computing tasks, is to break them into small, well defined manageable tasks. Divide and conquer.
This also applies to gui: break the design into small, easy to layout containers. For example:

enter image description here

You can see four fairly simple and distinct containers, named headerPane, listPane, inputPane and buttonsPane. The mainPane just warps (contains) those four.
The inputPane area is divided into containers, to keep the layout simple.

The idea is to keep each container layout simple, easy to follow and change.
headerPane can be as simple as:

JPanel headerPane = new JPanel(); //uses flow layout by default
JLabel header = new JLabel("LUNA BOOKSTORE ORDER FORM", JLabel.CENTER);
headerPane.add(header);

buttonsPane can be as simple as:

JPanel buttonsPane = new JPanel(); //uses flow layout by default
buttonsPane.add(new JButton("CONFIRM"));
buttonsPane.add(new JButton("RESET"));
buttonsPane.add(new JButton("EXIT"));

More examples of applying this strategy: 1 2 and 3

c0der
  • 18,467
  • 6
  • 33
  • 65
  • hey, I owe you a big time. This was a really big help and I learned smoothly how layouts work because of your guide. You saved me from a failed subject. Thank you so much!! – samo Apr 07 '19 at 05:14