java - 如何将 2 列复选框添加到 Jpanel
问题描述
我想在字符串和文本框下方以及按钮“Aceptar”和“Cancelar”上方的 2 列中添加几个(大约 8 个)复选框
我试图在另一个 Jpanel 中做一个 Jpanel,但我不工作,因为子面板没有对齐我想要的位置(或者我不知道如何对齐它)
JLabel texto_titulo_qliksense = new JLabel();
texto_titulo_qliksense.setText("Nombre del cuadro de mando :");
texto_titulo_qliksense.setBounds(20, 50, 700, 25);
JCheckBox checkBox1 = new JCheckBox("Stream 1");
checkBox1.setBounds(75,100, 50,50);
JCheckBox checkBox2 = new JCheckBox("Stream 2");
checkBox2.setBounds(10,150, 50,50);
textField = new JTextField(80);
textField.setBounds(200,53,220,20);
JLabel texto3 = new JLabel();
texto3.setText("Usuario: " + usuario);
JButton aceptar = new JButton();
aceptar.setText("Aceptar");
aceptar.setActionCommand(comandoAceptar);
aceptar.setBounds(90, 250, 100, 30);
aceptar.addActionListener(this);
JButton cancelar = new JButton();
cancelar.setText("Cancelar");
cancelar.setActionCommand(comandoCancelar);
cancelar.setBounds(250, 250, 100, 30);
cancelar.addActionListener(this);
panel = new JPanel();
panel.setBorder(null);
subpanel = new JPanel();
subpanel.setBorder(BorderFactory.createTitledBorder("Subpanel 1"));
subpanel.setBounds(250, 450, 250, 250);
subpanel.setAlignmentX(java.awt.Component.CENTER_ALIGNMENT);
subpanel.setAlignmentX(java.awt.Component.CENTER_ALIGNMENT);
subpanel.setVisible(true);
panel.setBounds(250, 100, 1000, 1000);
解决方案
它是一个非常小的程序,使用绝对定位会不会更容易?
比这容易吗?
JPanel ui = new JPanel(new BorderLayout(4,4));
ui.setBorder(new EmptyBorder(40,4,40,4));
JPanel pageStartPanel = new JPanel(new FlowLayout());
ui.add(pageStartPanel, BorderLayout.PAGE_START);
pageStartPanel.add(new JLabel("Nombre del cuadro de mando:"));
pageStartPanel.add(new JTextField(12));
JPanel checkPanel = new JPanel(new GridLayout(0,2));
ui.add(checkPanel, BorderLayout.CENTER);
for (int ii=1; ii<9; ii++) {
checkPanel.add(new JCheckBox("Checkbox " + ii));
}
JOptionPane.showConfirmDialog(
null,
ui,
"Exportar CdM de Qliksense",
JOptionPane.OK_CANCEL_OPTION);
推荐阅读
- flutter - flutter 如何从 API 获取谷歌地图标记并在谷歌地图上绘图
- flutter - Flutter 安装问题,无法接受带有字母 Y 或 y 的许可证
- python - 提交时Django和React总是错误请求
- javascript - 具有复制的类属性的 JS 编辑变量
- python - 为什么我的测试功能没有激活用户?
- c# - ClientWebsocket SSL 证书验证失败
- python - Python中DF的水平条形图
- azure-devops - Azure DevOps 管道任务以删除 AppService 设置中的密钥
- java - Cassandra - 启动期间遇到异常(java.lang.UnsatisfiedLinkError):找不到依赖库(jna626409071981896679.dll)
- javascript - 使用 sinon 存根私有函数