특정 형식의 JAVA GUI 제작에 대한 질문 (Question about making a JAVA GUI of a certain format)


문제 설명

특정 형식의 JAVA GUI 제작에 대한 질문 (Question about making a JAVA GUI of a certain format)

다음과 같은 GUI를 만들려고 합니다.

저는 5개의 버튼을 위한 공간이 있는 BorderLayout을 사용하는 방법만 알고 있습니다. 북쪽, 서쪽, 중앙, 동쪽 및 남쪽입니다.

최상단에 6개의 구성 요소가 있어야 하므로 이 접근 방식은 작동하지 않습니다. 맨 윗줄에 둘 이상의 구성 요소를 가질 수 있도록 만드는 방법을 모르겠습니다. 사용할 수 있는 다른 레이아웃이 있습니까? 아니면 BorderLayout을 조작하여 맨 윗줄에 6개의 구성 요소를 배치할 수 있습니까?


참조 솔루션

방법 1:

What you need to do is nest components inside of other components. For example, the top (North) should be one JPanel. That JPanel will contain the 6 components on the top.

The code may look similar to the following:

JPanel northPane = new JPanel();
northPane.add(new JLabel("Principle: "));
northPane.add(principleTextBox);
... and so on
mainPanel.setLayout(new BorderLayout());
mainPanel.add(northPanel, BorderLayout.NORTH);

The Center component will probably be another JPanel containing the two center buttons. And the South component will be another JPanel containing the single JLabel or simply the JLabel.

If you don't have to use a BorderLayout for the main panel, it may be easier to use a BoxLayout.

방법 2:

Once again I turn to miglayout, the absolute best layout manager for Java. No nested JPanels, just a simple layout using string based constraints.

alt text

With debug mode on: alt text

After resizing the window (note the ratio of the size of the textfields remains the same) alt text

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import net.miginfocom.swing.MigLayout;

/**
 *
 * @author nicholasdunn
 */
public class InterestCalculator extends JPanel {

    public InterestCalculator() {
        super(new MigLayout("debug, fill", "align center"));
        // Make 6 components cram into one cell
        add(new JLabel("Principal:"), "split 6");
        // This textfield grows at twice the normal rate
        add(new JTextField(), "growx 200");
        add(new JLabel("Interest rate (percentage):"));
        // This one at a normal rate
        add(new JTextField(), "growx 100");
        add(new JLabel("Years:"));
        // This one at half the normal rate
        add(new JTextField(), "growx 50, wrap");

        // The row with the two buttons
        add(new JButton("Compute simple interest"), "split 2");
        add(new JButton("Compute compound interest"), "wrap");

        // The result label
        add(new JLabel("The result with simple interest would be"));
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel panel = new InterestCalculator();
        frame.add(panel);
        frame.pack();
        frame.setVisible(true);
    }
}

방법 3:

If I were recreating that UI, I would start with a JPanel using a GridLayout with 3 rows and 1 column. In each column I would add a child JPanel.

Then for each row I would use a GridBagLayout to position the components.

방법 4:

Here is a tutorial about layout managers.

Remember that you can always add several elements to a JPanel and apply a specific layout to that JPanel. Then you can nest panels(add panels inside other panels).

(by GregjjnguyI82MuchRonnie HowellEnrique)

참조 문서

  1. Question about making a JAVA GUI of a certain format (CC BY‑SA 3.0/4.0)

#panel #components #swing #user-interface #java






관련 질문

R을 사용하여 패널 데이터의 마지막 이벤트 이후 실행 계산 (Using R to count a run since last event in panel data)

버튼을 클릭한 후 한 패널을 표시하고 동일한 프레임에서 두 번째 버튼을 클릭하면 다른 패널을 표시합니다. (show one panel after button is clicked and other panel when second button is clicked in the same frame)

외부를 클릭하면 패널을 닫아야 함(초점 상실) (Need To Close A Panel When Clicked Outside (Lost Focus))

asp.net gridview - updatepanel을 사용하여 행당 여러 줄에 바인딩된 데이터 분산 (asp.net gridview - spread bound data across multi lines per row with updatepanel)

문자를 포함하는 고유 식별자와 함께 xtreg 사용 (Using xtreg with unique identifier that includes letters)

matlab SVM은 NaN을 반환합니다. (matlab SVM returns NaN)

특정 형식의 JAVA GUI 제작에 대한 질문 (Question about making a JAVA GUI of a certain format)

슬라이딩 패널 구분선을 사용하여 HTML 페이지를 다른 섹션으로 분할하시겠습니까? 어떻게 이루어지나요? (Splitting HTML page into different sections using sliding panel dividers? How is it done?)

Swift Mac Os 응용 프로그램 - NSSavePanel이 '백그라운드 전용' 응용 프로그램에서 올바르게 작동하지 않습니다. (Swift Mac Os Application - NSSavePanel does not behave correctly with a 'background only' application)

Python 저주 update_panels() 및 Panel.move() 문제 (Python Curses update_panels() and Panel.move() issues)

stargazer를 사용하여 plm FE 회귀에서 전체 R2를 얻는 방법은 무엇입니까? (How to get between and overall R2 from plm FE regression with stargazer?)

Java, 패널용 그래픽 개체 생성 및 편집? (Java, create and edit a Graphics Object for Panel?)







코멘트