Files
swing-examples/doc/27_layout_manager.md
2024-03-30 19:57:14 +09:00

3.1 KiB

Layout Manager

  • component.setMinimumSize() / component.setMaximumSize() / component.setPreferredSize()

Border Layout

  • PAGE_START

  • PAGE_END

  • LINE_START

  • LINE_END

  • CENTER

  • container.add(Component,BorderLayout.CENTER)

  • setHGap(int) / setVGap(int)

Box Layout

  • LINE_AXIS
  • PAGE_AXIS

Box.Filler

  • Box.createRigidArea() : 컴포넌트 사이에 고정된 크기의 공간을 만들 때 사용합니다.

  • Box.createHorizontalGlue() / Box.createVerticalGlue() : 컴포넌트 사이에 최대한의 빈 공간을 만들고자 할 때 사용합니다.

  • Box.createHorizontalStrut() / Box.createVerticalStrut() : Strut보다는 RigidArea를 사용

  • new Box.Filler(Dimension,Dimension,Dimension) : 최소, 희망, 최대 크기.

  • changeShape(Dimension,Dimension,Dimension) : 레이아웃도 따라서 변경된다.

Card Layout

  • container.add(Component,String)

  • first(Container) / last(Container)

  • next(Container) / previous(Container)

  • show(Container,String)

Flow Layout

JPanel의 기본 레이아웃 매니저입니다.

  • LEADING

  • CENTER

  • TRAILING

  • setHGap(int) / setVGap(int)

  • setAlignment(int) : FlowLayout.LEADING | CENTER | TRAILING

Grid Bag Layout

  • add(Component,GridBagConstraints)

GridBagConstraints

  • gridx, gridy : 컴포넌트가 위치할 열과 행의 좌표를 지정한다. RELATIVE를 지정하면 이전 컴포넌트의 오른쪽이나 아래에 놓는다.
  • gridwidth, gridheight : 컴포넌트가 몇 칸을 차지할지를 지정한다. 기본 값은 1이다. 열이나 행의 마지막 컴퍼넌트에는 REMAINDER를 사용한다.
  • fill : 컴포넌트 보다 큰 공간을 어떻게 채울지를 지정한다. NONE | HORIZONTAL | VERTICAL | BOTH
  • ipadx, ipady : 컴포넌트 안쪽의 패딩 크기를 지정한다.
  • insets : 컴포넌트 외부의 패딩 크기를 지정한다.
  • anchor : CENTER | PAGE_START | PAGE_END | LINE_START | LINE_END | FIRST_LINE_START | FIRST_LINE_END | LAST_LINE_END | LAST_LINE_START
  • weightx, weighty : 컴포넌트가 어느 정도의 크기를 가질지 가중치를 지정한다. 0 ~ 1사이의 값을 지정하며, 기본값은 0이다.

Grid Layout

  • GridLayout(int,int) : 열과 행의 크기를 지정한다.

Group Layout

  • Horizontal group / Vertical group

  • Sequential group / Parallel group

  • addPreferredGap() / addContainerGap() : RELATED | UNRELATED | INDENT

  • setAutoCreateGaps(boolean) / setAutoCreateContainerGaps(boolean)

Spring Layout

  • NORTH

  • SOUTH

  • EAST

  • WEST

  • BASELINE

  • HORIZONTAL_CENTER

  • VERTICAL_CENTER

  • getConstraints(Component)

  • Spring getConstraint(String,Component)

  • putConstraint(String,Component,int,String,Component) / putConstraint(String,Component,Spring,String,Component)

SpringLayout.Constraints

  • getX() / getY() / getWidth() / getHeight() / setX() / setY() / setWidth() / setHeight()
  • getConstraint(String) / setConstraint(String,Spring)

Spring

  • constant(int) / constant(int,int,int)
  • Spring.sum(Spring,Spring) / Spring.max(Spring,Spring) / Spring.minus(Spring,Spring)
  • getValue() / setValue(int)