NguyenDat NguyenDat - 4 months ago 8
Java Question

How to build our own java custom layout

Please help me create my own custom layout, container, component, layout manager...
Example:
Containers and Layout Managers


  • Create a window frame.

  • Nest panels within a frame for better layout control.

  • Create and display buttons in a panel.

  • List two component attributes that are controlled by a layout manager.

  • Set the layout manager for a container.

  • Place components in a panel using BorderLayout, GridLayout, and FlowLayout.

  • Name one advantage of each of the layout managers.

  • Create panels with titles.



i was search on google but can't find any that match my requirement

Thanks for your help
Edit: I was found with keyword "Open Source UI"

Answer

Create a window frame

new JFrame();

Nest panels within a frame for better layout control

final JFrame jframe = new JFrame();
final JPanel innerOne = new JPanel();
jframe.add(innerOne);
innerOne.add(otherComponents);

Create and display buttons in a panel

innerOne.add(new JButton("Hello World!"));

List two component attributes that are controlled by a layout manager

Obviously check out JavaDoc of BorderLayout: BorderLayout.NORTH and SOUTH

Set the layout manager for a container

innerOne.setLayout(...);

Place components in a panel using BorderLayout, ...

Just apply the layout, and add providing the arguments for the LayoutManager:

innerOne.setLayout(new BorderLayout());
innerOne.add(..., BorderLayout.NORTH);

Name one advantage of each of the layoutmanager.

Check out the JavaDoc's. They are really helpful in these situations.

Create panels with titles.

innerOne.setBorder(new TitledBorder("Hello World"));