- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要帮助更改文本字段的大小。我在面板的开头有一个 JScrollPane (它很大,所以我可以读取更多数据),然后我有一个用于说明的 JLabel,最后我想添加一个 JTextArea,我只需要一行来输入数字。问题是面板中的元素相当大。我附上结果:
这是我的代码:
public static void delete()
{
int deletePosition;
String[] options = {"Confirm", "Cancel"};
JPanel panel = new JPanel();
JLabel label0 = new JLabel("Write the Position[#]:");
JLabel labelJump1 = new JLabel("");
JTextField txtDelete = new JTextField(1);
GridLayout gridLayout = new GridLayout(0,1);
panel.setLayout(gridLayout);
String fullText = "";
JTextArea textArea = new JTextArea(15,30);
textArea.setText(fullText);
textArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(textArea);
panel.add(scrollPane);
panel.add(label0);
panel.add(labelJump1);
panel.add(txtDelete);
try
{
if (theEntityCollection.checkEmpty())
JOptionPane.showMessageDialog(null, "The collection is EMPTY");
else
{
for(int i = 0 ; i < theEntityCollection.getArraySize() ; i++)
{
fullText += "Position [" + (i+1) + "]\n\n" + theEntityCollection.getEntity(i);
if (i != theEntityCollection.getArraySize() - 1)
fullText += "_____________________\n\n";
textArea.setText(fullText);
}
deletePosition = JOptionPane.showOptionDialog(null, panel, "ENTITY COLLECTION", JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options , options[0]);
}
}
catch(Exception e)
{
System.out.println("FAILED");
}
fullText = "";
}
我必须说我是 Java GUI 的新手。
如果您能帮助我,我将不胜感激!
最佳答案
GridLayout
正在执行其设计目的。它为每个组件提供完全相同的空间量,根据可用空间均匀分布。您可能需要使用更灵活的布局管理器,例如......
从改变开始...
GridLayout gridLayout = new GridLayout(0,1);
panel.setLayout(gridLayout);
类似...
GridBagLayout gridLayout = new GridBagLayout();
panel.setLayout(gridLayout);
GridBagConstraints gbc = new GridBagConstraints();
gbc.weightx = 1;
gbc.anchor = GridBagConstraints.WEST;
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.insets = new Insets(2, 2, 2, 2);
然后改变...
panel.add(scrollPane);
panel.add(label0);
panel.add(labelJump1);
panel.add(txtDelete);
更像是......
panel.add(scrollPane, gbc);
panel.add(label0, gbc);
panel.add(labelJump1, gbc);
panel.add(txtDelete, gbc);
看看Laying Out Components Within a Container和 How to Use GridBagLayout了解更多详情
关于java - 更改单个 JOptionPane 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33948947/
我正在使用 JOptionPane 来获取字符串。单击“确定”即可保存字符串。现在我希望弹出第二个 JOptionPane 以输入第二个必要的字符串。是否有机会将 ActionListener 添加到
我有一个显示来自 JOptionPane 的确认消息的过程。此过程从 JMenuItem 的 Actionlistener 内的 SwingUtilities.invokeLater(runnable
我使用以下代码来获取InputDialog: String c = JOptionPane.showInputDialog("Select number",JOptionPane.OK_OPTION)
正如你从我上面的主题中看到的, 我想知道我怎么能解雇一个 JOptionPane 因为另一个 JOptionPane 而变得无关紧要,因为用户出于某种原因没有通过自己点击确定按钮(例如)解雇第一个。
没有收到“文件已成功接收”消息,请帮助我。将文件从客户端传输到服务器时,即使文件已收到,也不会显示该消息。 这是使用套接字将文件从客户端传输到服务器的程序,接口(interface)也是使用java
JOptionPane.showInputDialog 有一个不需要父组件参数的表单。 JOptionPane.showConfirmDialog 确实如此。这是为什么? 最佳答案 JOptionPa
我正在用 Java 创建一个基于 Tic Tac Toe GUI 的游戏,并且正在努力将 2D 数组与 JOptionPane 结合使用。到目前为止,我已经能够创建可供选择的按钮: import ja
使用 JOprionPane 时,光标出现了一些问题。我将光标设置到 pharent 框架,然后使用这个显示一个对话框: Object[] possibilities = {"ham", "spam"
我创建了一个打开 JOptionPane 的按钮。它允许用户输入 string..>> String str = JOptionPane.showInputDialog 如何获取用户输入到 jopti
该代码正在运行。但问题是,当选择 NO_OPTION 时,窗口就会被释放。我想在选择 NO_OPTION 时保留窗口?你能给点建议吗? int dialogButton = JOptionPa
我正在 Java 上开发 Tic Tac Toe 游戏(eclipse)。在我的计算机上,我的对话框非常小。我一直在努力把它做得更大。我没有任何运气。我希望这里有人能引导我走向正确的方向。下面的代码是
我正在使用脚本 API 为我玩的游戏的机器人制作脚本,但是每当我覆盖机器人管理器时,就会出现一个 JOptionPane 来阻止执行,直到我关闭它,但是我想在不运行该脚本的情况下运行此脚本人为干预,所
我正在用 Java 开发一个游戏,我试图在 JOptionPane 确认框打开时暂停它。这是代码: window.addWindowListener(new WindowAdapter() {
这个问题已经有答案了: Calling one JFrame from another using Timer without any buttons (1 个回答) 已关闭 9 年前。 需要帮助制作
很抱歉代码这么长,我只需要知道我缺少什么来初始化我的所有决定。编译器提示我的变量没有被初始化。谢谢你。 import javax.swing.JOptionPane; public class Sem
我想使用 JOptionPane 处理一些异常。这是主要方法: public class MainRun { public static void main(String args[]){
不允许使用数组,该函数正在工作,但只是返回 0,就好像它没有计算正确的输入字符一样,但现在它给了我一个“字符串超出范围:3” 这应该运行,打开一个窗口,要求我输入一个字符串,在本例中是一个单词,然后打
我正在使用 Jfilechooser,如果我选择文件,它将计算文件名的字符数,但是如果文件超过 3kb,它将限制 Joptionpane 将显示。我的问题是即使文件是0kb,Joptionpane也会
我创建了一个应用于框架的名为 addSupplier 的按钮,然后创建了一个操作监听器,因此一旦按下 addSupplier 按钮,它将创建一个 JOptionPane,其中有一个附加了 JTextF
我知道解决方案是使用 for 循环来逐步遍历数组并显示在 Pane 中。但是我没有找到对此的直接解释。我需要一个下一个和一个上一个按钮来显示每个数组元素,并且在按下下一个按钮时到达第一个元素后仅返回到
我是一名优秀的程序员,十分优秀!