简体   繁体   English

单击按钮时的java swing jpanel显示

[英]java swing jpanel display when clicking a button

i'm new to swing. 我是新来的。 i've created a jpanel form using the swing palette design. 我使用摇摆调色板设计创建了一个jpanel表单。 It has jlabels, jtextfields and a jbutton. 它具有jlabels,jtextfields和一个jbutton。 when the button is clicked, the data entered in the jtextfields is inserted in the database through the model. 单击该按钮时,在jtextfields中输入的数据将通过模型插入数据库中。

i don't want the the jpanel to be always displayed so i would like to add another button that displays this jpanel form when i click on it. 我不希望jpanel始终显示,因此我想添加另一个按钮,当我单击它时显示此jpanel表单。 is it possible to perform this using the palette design knowing that the source code is locked in the initComponent private function, or do i have to re-code all the components and layout myself? 是否可以使用调色板设计来执行此操作,而知道源代码已锁定在initComponent私有函数中,或者我是否必须重新编码所有组件并自己进行布局?

thanks for your time! 谢谢你的时间!

"knowing that the source code is locked in the initComponent private function" “知道源代码已锁定在initComponent私有函数中”

You can edit the auto-generated source code, as see here in this answer . 您可以编辑自动生成的源代码, 如此答案此处所示

"that displays this jpanel form when i click on it. is it possible to perform this using the palette design" “当我单击它时会显示此jpanel表单。是否可以使用调色板设计来执行此操作?”

Sounds like you want to swap views. 听起来好像您想交换视图。 You can do that using CardLayout and yes, it can be done from the design view. 您可以使用CardLayout做到这一点,是的,可以从设计视图中完成。 You can see more at How to Use CardLayout with Netbeans GUI Builder 您可以在如何与Netbeans GUI Builder一起使用CardLayout中看到更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM