我决定尝试 JFormDesigner 来设计我的应用程序用户界面。
我通过IntelliJ Idea插件设置了我的GUI,并获得了通常自动生成的代码:
package dataParser.View;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import net.miginfocom.swing.*;
public class MainView extends JFrame {
public MainView() {
initComponents();
pack();
}
private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
ResourceBundle bundle = ResourceBundle.getBundle("dataParser.Resources.strings");
mainFrame = new JFrame();
tabbedPanel = new JTabbedPane();
apachePanel = new JSplitPane();
leftSideSplitPanel = new JSplitPane();
mySqlPanel = new JPanel();
mySqlPortLabel = new JLabel();
mySqlPortTextField = new JFormattedTextField();
usernameField = new JLabel();
usernameTextField = new JFormattedTextField();
passwordLabel = new JLabel();
passwordTextField = new JFormattedTextField();
mySqlApplyButton = new JButton();
mySqlTestButton = new JButton();
servicesPanel = new JPanel();
apacheButton = new JButton();
mySqlButton = new JButton();
rightSidePanel = new JSplitPane();
controlUnitPanel = new JPanel();
cuIpLabel = new JLabel();
cuIpTextField = new JFormattedTextField();
cuPortLabel = new JLabel();
cuPortTextField = new JFormattedTextField();
cuApplyButton = new JButton();
cutestButton = new JButton();
logScrollPanel = new JScrollPane();
scrollTextPanel = new JTextPane();
panel10 = new JPanel();
//======== mainFrame ========
{
mainFrame.setAlwaysOnTop(true);
mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
mainFrame.setResizable(false);
Container mainFrameContentPane = mainFrame.getContentPane();
//======== tabbedPanel ========
{
//======== apachePanel ========
{
apachePanel.setResizeWeight(0.4);
//======== leftSideSplitPanel ========
{
leftSideSplitPanel.setOrientation(JSplitPane.VERTICAL_SPLIT);
leftSideSplitPanel.setResizeWeight(0.5);
//======== mySqlPanel ========
{
mySqlPanel.setBackground(Color.white);
mySqlPanel.setBorder(new TitledBorder(LineBorder.createBlackLineBorder(), bundle.getString("MainView.mySqlPanel.border"), TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION,
new Font("Tahoma", Font.BOLD, 11)));
mySqlPanel.setLayout(new MigLayout(
"fill,insets panel,hidemode 3",
// columns
"[fill]" +
"[fill]",
// rows
"[]" +
"[]" +
"[]" +
"[]"));
//---- mySqlPortLabel ----
mySqlPortLabel.setText(bundle.getString("MainView.mySqlPortLabel.text"));
mySqlPortLabel.setHorizontalAlignment(SwingConstants.CENTER);
mySqlPanel.add(mySqlPortLabel, "cell 0 0,alignx center,growx 0");
//---- mySqlPortTextField ----
mySqlPortTextField.setHorizontalAlignment(SwingConstants.CENTER);
mySqlPanel.add(mySqlPortTextField, "cell 1 0");
//---- usernameField ----
usernameField.setText(bundle.getString("MainView.usernameField.text"));
usernameField.setHorizontalAlignment(SwingConstants.CENTER);
mySqlPanel.add(usernameField, "cell 0 1,alignx center,growx 0");
//---- usernameTextField ----
usernameTextField.setHorizontalAlignment(SwingConstants.CENTER);
mySqlPanel.add(usernameTextField, "cell 1 1");
//---- passwordLabel ----
passwordLabel.setText(bundle.getString("MainView.passwordLabel.text"));
passwordLabel.setHorizontalAlignment(SwingConstants.CENTER);
mySqlPanel.add(passwordLabel, "cell 0 2,alignx center,growx 0");
//---- passwordTextField ----
passwordTextField.setHorizontalAlignment(SwingConstants.CENTER);
mySqlPanel.add(passwordTextField, "cell 1 2");
//---- mySqlApplyButton ----
mySqlApplyButton.setText(bundle.getString("MainView.mySqlApplyButton.text"));
mySqlPanel.add(mySqlApplyButton, "cell 0 3");
//---- mySqlTestButton ----
mySqlTestButton.setText(bundle.getString("MainView.mySqlTestButton.text"));
mySqlPanel.add(mySqlTestButton, "cell 1 3");
}
leftSideSplitPanel.setTopComponent(mySqlPanel);
//======== servicesPanel ========
{
servicesPanel.setBackground(Color.white);
servicesPanel.setBorder(new TitledBorder(LineBorder.createBlackLineBorder(), bundle.getString("MainView.servicesPanel.border"), TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION,
new Font("Tahoma", Font.BOLD, 11)));
servicesPanel.setLayout(new MigLayout(
"fill,hidemode 3",
// columns
"[fill]",
// rows
"[]" +
"[]"));
//---- apacheButton ----
apacheButton.setText(bundle.getString("MainView.apacheButton.text"));
servicesPanel.add(apacheButton, "cell 0 0");
//---- mySqlButton ----
mySqlButton.setText(bundle.getString("MainView.mySqlButton.text"));
servicesPanel.add(mySqlButton, "cell 0 1");
}
leftSideSplitPanel.setBottomComponent(servicesPanel);
}
apachePanel.setLeftComponent(leftSideSplitPanel);
//======== rightSidePanel ========
{
rightSidePanel.setOrientation(JSplitPane.VERTICAL_SPLIT);
rightSidePanel.setResizeWeight(0.5);
//======== controlUnitPanel ========
{
controlUnitPanel.setBackground(Color.white);
controlUnitPanel.setBorder(new TitledBorder(LineBorder.createBlackLineBorder(), bundle.getString("MainView.controlUnitPanel.border"), TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION,
new Font("Tahoma", Font.BOLD, 11)));
controlUnitPanel.setLayout(new MigLayout(
"fill,insets panel,hidemode 3",
// columns
"[fill]" +
"[fill]",
// rows
"[]" +
"[]" +
"[]"));
//---- cuIpLabel ----
cuIpLabel.setText(bundle.getString("MainView.cuIpLabel.text"));
cuIpLabel.setHorizontalAlignment(SwingConstants.CENTER);
controlUnitPanel.add(cuIpLabel, "cell 0 0,alignx center,growx 0");
//---- cuIpTextField ----
cuIpTextField.setHorizontalAlignment(SwingConstants.CENTER);
controlUnitPanel.add(cuIpTextField, "cell 1 0");
//---- cuPortLabel ----
cuPortLabel.setText(bundle.getString("MainView.cuPortLabel.text"));
cuPortLabel.setHorizontalAlignment(SwingConstants.CENTER);
controlUnitPanel.add(cuPortLabel, "cell 0 1,alignx center,growx 0");
//---- cuPortTextField ----
cuPortTextField.setHorizontalAlignment(SwingConstants.CENTER);
controlUnitPanel.add(cuPortTextField, "cell 1 1");
//---- cuApplyButton ----
cuApplyButton.setText(bundle.getString("MainView.cuApplyButton.text"));
controlUnitPanel.add(cuApplyButton, "cell 0 2");
//---- cutestButton ----
cutestButton.setText(bundle.getString("MainView.cutestButton.text"));
controlUnitPanel.add(cutestButton, "cell 1 2");
}
rightSidePanel.setTopComponent(controlUnitPanel);
//======== logScrollPanel ========
{
logScrollPanel.setViewportView(scrollTextPanel);
}
rightSidePanel.setBottomComponent(logScrollPanel);
}
apachePanel.setRightComponent(rightSidePanel);
}
tabbedPanel.addTab(bundle.getString("MainView.apachePanel.tab.title"), apachePanel);
//======== panel10 ========
{
panel10.setLayout(new MigLayout(
"fill,hidemode 3",
// columns
"[fill]" +
"[fill]",
// rows
"[]" +
"[]" +
"[]"));
}
tabbedPanel.addTab(bundle.getString("MainView.panel10.tab.title"), panel10);
}
GroupLayout mainFrameContentPaneLayout = new GroupLayout(mainFrameContentPane);
mainFrameContentPane.setLayout(mainFrameContentPaneLayout);
mainFrameContentPaneLayout.setHorizontalGroup(
mainFrameContentPaneLayout.createParallelGroup()
.addGroup(mainFrameContentPaneLayout.createSequentialGroup()
.addContainerGap()
.addComponent(tabbedPanel)
.addContainerGap())
);
mainFrameContentPaneLayout.setVerticalGroup(
mainFrameContentPaneLayout.createParallelGroup()
.addGroup(mainFrameContentPaneLayout.createSequentialGroup()
.addContainerGap()
.addComponent(tabbedPanel)
.addContainerGap())
);
mainFrame.setSize(655, 520);
mainFrame.setLocationRelativeTo(null);
}
// JFormDesigner - End of component initialization //GEN-END:initComponents
}
}
// JFormDesigner - Variables declaration - DO NOT MODIFY
private JFrame mainFrame;
private JTabbedPane tabbedPanel;
private JSplitPane apachePanel;
private JSplitPane leftSideSplitPanel;
private JPanel mySqlPanel;
private JLabel mySqlPortLabel;
private JFormattedTextField mySqlPortTextField;
private JLabel usernameField;
private JFormattedTextField usernameTextField;
private JLabel passwordLabel;
private JFormattedTextField passwordTextField;
private JButton mySqlApplyButton;
private JButton mySqlTestButton;
private JPanel servicesPanel;
private JButton apacheButton;
private JButton mySqlButton;
private JSplitPane rightSidePanel;
private JPanel controlUnitPanel;
private JLabel cuIpLabel;
private JFormattedTextField cuIpTextField;
private JLabel cuPortLabel;
private JFormattedTextField cuPortTextField;
private JButton cuApplyButton;
private JButton cutestButton;
private JScrollPane logScrollPanel;
private JTextPane scrollTextPanel;
private JPanel panel10;
}
之后,在我的 MainClass 中,我已经设置了我的主要方法:
public static void main(String[] args) {
[...]
javax.swing.SwingUtilities.invokeLater(() -> {
MainView GUI = new MainView();
GUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GUI.setVisible(true);
});
}
然而,当我启动我的应用程序时,我只能看到这个
然后当我放大JFrame时这个。
我查看了类似的问题,例如this one,但我无法解决这个问题。任何提示? 谢谢!
编辑
添加
this.setContentPane(this.tabbedPanel);
在自动生成的 initComponents()方法的最后,我终于看到了与我用插件设计的东西相似的东西。尽管如此,我还是不认为我应该修改这种方法,当它清楚地说: // JFormDesigner - 组件初始化 - 不要修改
而且,这就是我所看到的
我应该看看这个: