gpt4 book ai didi

java - 带有可滚动对象的 JDialog

转载 作者:行者123 更新时间:2023-12-02 02:31:04 25 4
gpt4 key购买 nike

我正在使用一个组件对象,然后在 Jdialog 中调用,但我想让它可滚动,因为由于组件数量较多,它在屏幕中占用了足够的空间。我找到了许多文本区域滚动的解决方案,但与我无关。

//Object of components
Object[] Payments = {
"For Max-cost 14 (Applied to all currencies):", er1,
"For Max-cost 12 (Applied to all currencies)", er2,
"For Max-cost 10.5 (Applied to all currencies)",er105,
"For Max-cost 10 (Applied to all currencies)", er10,
"For Max-cost 9 (Applied to all currencies)", er9,
"For Max-cost 8.25 (Applied to all currencies)",er825,
"For Max-cost 8 (Applied to all currencies)", er8,
"For Max-cost 7 (Applied to all currencies)", er7,
"For Max-cost 6.75 (Applied to all currencies)",er675,
"For Max-cost 6 (Applied to all currencies)", er3,
"For Max-cost 5 (Applied to all currencies)", er6,
"For Max-cost 4 (Applied to all currencies)", er4,
"For Max-cost 3.75 (Applied to all currencies)",er375,
};
//calling dialog
JOptionPane.showConfirmDialog(null, Payments, "Set Amount for different job-budget", JOptionPane.OK_CANCEL_OPTION);

最佳答案

这会有所帮助

public static void main(String[] args) {
ScrollDialog dialog = new ScrollDialog();
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
}

public static class ScrollDialog extends JDialog {
private JScrollPane scrollPane = new JScrollPane();
private JPanel innerPane = new JPanel();

public ScrollDialog() {
this.setSize(400, 400);
this.setLocationRelativeTo(null);
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(scrollPane, BorderLayout.CENTER);
this.innerPane.setPreferredSize(new Dimension(100, 800));
this.scrollPane.setViewportView(innerPane);
}
}

在“innerPane”中添加您想要的内容。快乐编码:)

关于java - 带有可滚动对象的 JDialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57230273/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com