如何创建一个JTabbedPane java?

发布于 2024-10-31 18:02:23 字数 632 浏览 1 评论 0原文

我有一个 imageViewer,我想将 imagePanel 更改为 TabbedPane,这样我就可以同时打开多个图像,但将每个图像放在不同的选项卡中,并且还能够添加和删除选项卡。

我有什么:

private ImagePanel imagePanel; //<<我尝试将 ImagePanel 更改为 JTabbedPane 但它不起作用,并且在我拥有的代码的其他部分中给出了错误。

// 在中心创建图像窗格

imagePanel = new ImagePanel(); imagePanel.setBorder(new EtchedBorder()); contentPane.add(imagePanel, BorderLayout.CENTER);

上面的代码适用于显示图像的图像窗格。 是否可以将图像窗格更改为 tabbedPane 而不更改代码中的其他位? 我已经看过很多选项卡示例,但我不知道如何将代码与我的代码结合起来以使其工作,但我确实将一些代码示例放入我的程序中,但框架更改为选项卡窗格而不是图像窗格,其中显示图像。我想将内部框架更改为选项卡式而不是程序的实际框架。 关于我应该如何去做的任何建议,或者您是否可以向我展示一个可行的简单示例。

谢谢

i have an imageViewer and i want to change the imagePanel into a TabbedPane so i can have more than one image open at the same time but have each of them in a different tab and be able to add and remove the tabs as well.

what i have:

private ImagePanel imagePanel; //<< i tried to change the ImagePanel to JTabbedPane but it doesn't work and it gives error in other parts of the codes that i have.

// Create the image pane in the center

imagePanel = new ImagePanel();
imagePanel.setBorder(new EtchedBorder());
contentPane.add(imagePanel, BorderLayout.CENTER);

the code above is for the image pane where the image is displayed.
is it possible to change the image pane to a tabbedPane without changeing other bits in the code?
i have looked at alot of tabbedpane examples but i don't know how to combine the code with my code to get it to work but i did put a few code examples into my program but the frame changes to tabbedpane and not the image pane where the image is displayed. i want to change the inner frame to tabbed not the actual frame of the program.
any suggestions on how should i go about it or if you can show me a simple example that could work.

thank you

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

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

发布评论

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

评论(1

夜巴黎 2024-11-07 18:02:23

我想您的 ImagePanel 扩展了 JPanel。您不会将其“更改”为 JTabbedPane,事实上您也不能,而是将其放入 JTabbedPane 中。请查看有关选项卡式窗格的教程,该教程将向您展示如何执行此操作:如何使用选项卡式窗格

需要注意的是:如果您使用 NetBeans 拖放 GUI 创建工具来生成 Swing 代码,我建议您不要这样做,而应该阅读 Swing 教程(其中一个链接为到上面)并学习手动编写 Swing 代码。您不会后悔的,如果以后您需要使用 NetBeans 工具创建 gui,则可以使用所获得的额外知识。

I imagine that your ImagePanel extends JPanel. You don't "change" this into a JTabbedPane, and in fact you can't, but rather you put it into a JTabbedPane. Please check out the tutorial on tabbed panes that will show you how to do this: How to use Tabbed Panes

One caveat: if you are using NetBeans drag-and-drop GUI creation tools to generate your Swing code, I advise you not to do this but rather to go through the Swing tutorials (one is linked to above) and learn to code Swing by hand. You won't regret this, and the extra knowledge gained can be used if later you need to create gui's with the NetBeans tool.

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