java - J内部框架组件未初始化
问题描述
您好,我是 Java 新手,最近尝试从使用 netbeans IDE 转为使用原始代码来制作我的 JIternalFrames,但它显示时要么没有组件,要么根本不显示。
为了纠正这个问题,我试图改变我设置组件的顺序,例如我最初将它设置为 initvariables > addcomponentstopanes > setsizes/text > setvisible,我也尝试过使用 repaint() 和 revalidate() 到 no利用。
package tester;
import java.awt.Font;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
public class TestChunk extends javax.swing.JInternalFrame
{
JInternalFrame consumeWindow;
JScrollPane coScrollPane;
JPanel panel;
JButton eatBerriesButton, eatMushroomsButton, eatFishButton;
public void startComponents()
{
consumeWindow = new JInternalFrame("Consume Panel");
panel = new JPanel();
eatBerriesButton = new JButton();
eatMushroomsButton = new JButton();
eatFishButton = new JButton();
GridLayout myLayout;
consumeWindow.setBorder(null);
consumeWindow.setResizable(true);
myLayout = new GridLayout(0, 3, 10, 5);
panel.setLayout(myLayout);
consumeWindow.setSize(500, 325);
panel.setSize(500, 650);
eatBerriesButton.setBounds(5, 5, 150, 50);
eatMushroomsButton.setBounds(5, 60, 150, 50);
eatFishButton.setBounds(5, 105, 150, 50);
panel.add(eatMushroomsButton);
panel.revalidate();
panel.repaint();
panel.add(eatBerriesButton);
panel.revalidate();
panel.repaint();
panel.add(eatFishButton);
panel.revalidate();
panel.repaint();
coScrollPane = new JScrollPane(panel);
coScrollPane.setSize(500, 325);
coScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
coScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
consumeWindow.setContentPane(coScrollPane);
consumeWindow.revalidate();
consumeWindow.repaint();
consumeWindow.setVisible(true);
consumeWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
问题是我最新的 JInternalFrame(完全用代码编写的)没有显示,当我让它显示时,它没有任何组件。当前的内部框架应该在 JScrollPane 中包含 3 个按钮,每个按钮之间大约有 5 个间隙。(如果您想要更多代码进行说明,请随时提出要求)。
解决方案
推荐阅读
- pyspark - 在 Databricks 上的 DBFS 中打开文件会引发错误
- google-app-engine - 为什么我的 Google App Engine 预安装脚本由于 Ubuntu (security.ubuntu.com) 返回 404 而失败?
- r - 是否有一个 R 函数可以在给定日期添加周末星期天
- javascript - 为什么这个着色器圆比通过的半径小这么多?
- r - R预测:寓言包,多元分解模型
- awk - 在 awk 中使用通配符和对文件的引用
- git - 使用合并提交将提交移动到新分支
- python - 不和谐机器人如何使用同一代码中的功能之一?
- scala - 如何使用 spark scala 删除 csv 文件中的字符?
- opencv - 我需要安装所有这 3 个库还是只安装一个?开放式CV