我从来没有使用过网格袋布局,但我相信它可能是别的东西。目前,我正在尝试添加一个 TextArea,以充当正在执行的任何代码的控制台视口窗口。就目前而言,文本区域很小,实际上看不到任何文本。
我尝试查阅此页面以获取其中一个建议,但我仍然无法正确显示JTextArea。
代码粘贴在下面,如果您需要其他任何内容,请告诉我。我还附上了一张额外的图片,显示了它目前正在做什么。编辑:设置(); 是一个空的正文。
@SuppressWarnings("serial")
public abstract class MainComponent extends JPanel {
protected String componentName = "DEMO";
private JLabel title;
private GridBagConstraints gbc;
private Insets spacing;
private Font buttonFont;
/*
* Redirection manipulation for the project.
*/
private JTextArea localConsole;
public MainComponent(Dimension dim) {
setup();
/* Set main body */
setLayout(new GridBagLayout());
gbc = new GridBagConstraints();
spacing = new Insets(100,5,100,5);
buttonFont = new Font("Consolas", Font.ITALIC, 22);
/* Set title */
title = new JLabel(componentName);
title.setFont(new Font("Consolas", Font.BOLD, 48));
gbc.fill = GridBagConstraints.CENTER;
gbc.gridx = 1;
gbc.gridy = 0;
add(title, gbc);
JButton run = new JButton("Run Project");
run.setFont(buttonFont);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = spacing;
gbc.gridx = 0;
gbc.gridy = 2;
add(run, gbc);
JButton open = new JButton("Open Codebase");
open.setFont(buttonFont);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = spacing;
gbc.gridx = 1;
gbc.gridy = 2;
add(open, gbc);
JButton exit = new JButton("Exit Program");
exit.setFont(buttonFont);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = spacing;
gbc.gridx = 2;
gbc.gridy = 2;
add(exit, gbc);
}

慕仙森
相关分类