如何在同一框架上添加可编辑的 JComboBox 和按钮..?

发布于 2024-12-27 17:38:23 字数 210 浏览 3 评论 0原文

我创建了一个包含 5 列的 JTable。我希望第六列将所有单元格作为 JComboBox,用户可以从中选择他的选择,并且更改将附加到数据库中,为此我需要一个按钮,在其上我可以触发该按钮查询我的数据库。所以请让我知道如何在 JFrame 上添加 JComboBox 和 Button...??我对 Swings 很陌生,所以请让我知道如何完成此操作,对此的详细解释将非常感激......!提前致谢..!!!

I have created a JTable with 5 columns in it .I want the sixth column to have all cells as JComboBox from where an user can select his choice and the change will get appended in databasefor which i need a button on whose action i can fire the query to my database. So please please let me know how to add JComboBox and ButTon on JFrame...?? I am very new to Swings so do let me know how to get this donea detailed explanation about the same will be very thankful...!!! Thanks in advance..!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紙鸢 2025-01-03 17:38:23

如何在 JFrame 上添加 JComboBoxJButton 相当简单。我无法将这个问题与表格中问题的第一部分联系起来。但对于我确实理解的部分,您可以使用类似的

JFrame frame = new JFrame( "TestFrame" );

JPanel contents = new JPanel( new BorderLayout() );

JComboBox comboBox = createComboBox();
contents.add( comboBox, BorderLayout.CENTER );

JButton button = createButton();
contents.add( button, BorderLayout.EASTH );

frame.add( contents );

frame.pack();
frame.setVisible( true );

代码说明如何添加组合框和按钮。请注意,我选择了非常简单的 BorderLayout。其他布局当然也是可能的,但这完全取决于布局的要求。

How to add JComboBox and JButton on a JFrame is rather trivial. Linking this question to the first part of your question with the table is something I did not manage. But for the part I did understand, you can have something like

JFrame frame = new JFrame( "TestFrame" );

JPanel contents = new JPanel( new BorderLayout() );

JComboBox comboBox = createComboBox();
contents.add( comboBox, BorderLayout.CENTER );

JButton button = createButton();
contents.add( button, BorderLayout.EASTH );

frame.add( contents );

frame.pack();
frame.setVisible( true );

The code illustrates how to add a combobox and a button. Note that I opted for the very simple BorderLayout. Other layouts are certainly possible, but it all depends on the requirements of your layout.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文