将 jpanel 添加到 jframe 中。网豆
我特别使用netbeans gui编辑器,我是gui的新手,
我创建了一个jframe,并添加了jtabbedpanel。
在 jtabbedpanel 内部,我有 2 个面板,我称之为标准面板和紧凑面板,
我设置了 standardPanel = new ImagePanel();哪个 ImagePanel.java 位于不同的 java 文件上,
我该如何将面板放在不同的文件上以实现可重用性?
我显然不希望所有代码都在一个文件中。
这是设计 GUI 的正确方法吗?
谢谢
i am particularly using netbeans gui editor and i am new to gui
i have a jframe created and I added jtabbedpanel.
inside the jtabbedpanel i have 2 panels that i call standard and compact
i have set standardPanel = new ImagePanel(); which ImagePanel.java is located on different java file
how am I suppose to put a panel on different file for reusability ?
i obviously dont want all the codes in a single file.
is this the right way to design a gui ?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该创建自己的类,例如从 JPanel 扩展的“CustomPanel”。您将该类放入其自己的文件中,JPanel 上的所有内容都应该是该类的一部分。
然后,您不是将 JPanel 添加到选项卡式面板,而是创建 CustomPanel 的实例并将其添加到选项卡式面板。
You should create your own class, something like "CustomPanel" that extends from JPanel. You put that class in its own file, and everything that goes on the JPanel should be a part of that class.
Then, instead of adding a JPanel to the tabbed panel, you create an instance of CustomPanel and add it to the tabbed panel.