gpt4 book ai didi

java - JFrame 布局帮助/指南,

转载 作者:行者123 更新时间:2023-12-02 04:40:16 24 4
gpt4 key购买 nike

我的 JFRAME 布局遇到问题布局对我来说非常困难,因为我刚刚开始学习它。我正在寻找的布局是
选择数据开始
DAY:“文本字段”
月份:“textField”
年份:“文本字段”
结束日期
DAY:“文本字段”
月份:“textField”
年份:“文本字段”

好像已经到了最后阶段,为什么 top 不工作

JFRAME

下面的代码显示了上面的图片

import javax.swing.*;
import java.awt.Dialog.ModalityType;
import java.awt.event.*;
import java.awt.*;

public class TopUpHistoryScreen extends JDialog {

private JPanel mainPanel;
private JTextArea historyScreen;

public TopUpHistoryScreen()
{
setPanels();

setModalityType(ModalityType.APPLICATION_MODAL);
setSize(600, 600);
setVisible(true);
}
public void setPanels()
{
mainPanel = new JPanel(new GridLayout(0, 2));
JPanel containerPanel = new JPanel(new GridLayout(0, 1));
JPanel lowerPanel = new JPanel(new FlowLayout());
//JButton apply = new JButton("Select data area");
JButton exit = new JButton("Okay!");
exit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
dispose();
}
});
JButton checkDate = new JButton("check dates");

JLabel SelectData = new JLabel("Select data area\n");
JLabel START = new JLabel("START DATE!");
JLabel startDay = new JLabel("Day:");
JTextField sDay = new JTextField();

JLabel startMonth = new JLabel("Month:");
JTextField sMonth = new JTextField();

JLabel startYear = new JLabel("Year:");
JTextField sYear = new JTextField();

JLabel END = new JLabel("END DATE!");

JLabel endDay = new JLabel("Day:");
JTextField eDay = new JTextField();

JLabel endMonth = new JLabel("Month:");
JTextField eMonth = new JTextField();

JLabel endYear = new JLabel("Year:");
JTextField eYear = new JTextField();

JTextField Data = new JTextField();
JTextField touchOnTimeFieldminute = new JTextField();

historyScreen = new JTextArea(5,30);
JScrollPane scrolll = new JScrollPane(historyScreen);

mainPanel.add(SelectData);
mainPanel.add(START);
mainPanel.add(startDay);
mainPanel.add(sDay);
mainPanel.add(startMonth);
mainPanel.add(startYear);
mainPanel.add(sYear);
mainPanel.add(END);
mainPanel.add(endDay);
mainPanel.add(eDay);
mainPanel.add(endMonth);
mainPanel.add(eMonth);
mainPanel.add(endYear);
mainPanel.add(eYear);
mainPanel.add(checkDate);
//mainPanel.add(touchOnTimeFieldhour);
//mainPanel.add(SelectData);
//mainPanel.add(touchOnTimeFieldminute);
//mainPanel.add(touchOnTimem);
lowerPanel.add(scrolll);
lowerPanel.add(exit);
//lowerPanel.add(apply);
//touchOnTimeFieldhour.setSize(10,10);
containerPanel.add(mainPanel);
containerPanel.add(lowerPanel);

add(containerPanel);
}
}

最佳答案

setPanels() 方法中的 mainPanel.add(component); 序列更改为以下内容..

    mainPanel.add(SelectData);
mainPanel.add(START);
mainPanel.add(startDay);
mainPanel.add(sDay);
mainPanel.add(startMonth);
mainPanel.add(sMonth);
mainPanel.add(startYear);
mainPanel.add(sYear);
mainPanel.add(END);
mainPanel.add(new JLabel());
mainPanel.add(endDay);
mainPanel.add(eDay);
mainPanel.add(endMonth);
mainPanel.add(eMonth);
mainPanel.add(endYear);
mainPanel.add(eYear);
mainPanel.add(checkDate);

它会起作用..当您使用 GridViewmainPanel 时,元素将根据您将其添加到 mainPanel 的顺序获取位置...

关于java - JFrame 布局帮助/指南,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30264817/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com