如何使用 TabbedPane 选项卡更改在 NetBeans IDE 内置的 Applet 中显示不同的面板?

发布于 2024-09-28 17:22:50 字数 233 浏览 6 评论 0原文

我正在 NetBeans 中构建一个 Java Applet,该 Applet 的底部有一个 TabbedPane,顶部有一个常规面板。我希望顶部面板根据底部选择的选项卡进行切换。 (我会附上一个屏幕截图来澄清,但这里是新的,这是不允许的。)

按钮有 ActionPerformed,但 TabbedPane 似乎没有每个单独选项卡的 StateChange(至少在 NetBeans 中不容易看到) 。

有什么想法吗?

I'm building a Java Applet in NetBeans that has a TabbedPane on the bottom of the applet and a regular Panel on the top. I would like the top Panel to switch depending on which tab is selected on the bottom. (I would attach a screenshot to clarify, but being new here it isn't allowed.)

A Button has ActionPerformed, but a TabbedPane doesn't seem to have StateChange for each of the seperate tabs (at least not readily visible in NetBeans).

Any ideas?

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

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

发布评论

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

评论(1

百思不得你姐 2024-10-05 17:22:50

根据这里,你可以这样做:

// Create the tabbed pane
JTabbedPane pane = new JTabbedPane();

// Add tabs...; see Adding a Tab to a JTabbedPane Container

// Register a change listener
pane.addChangeListener(new ChangeListener() {
    // This method is called whenever the selected tab changes
    public void stateChanged(ChangeEvent evt) {
        JTabbedPane pane = (JTabbedPane)evt.getSource();

        // Get current tab
        int sel = pane.getSelectedIndex();
    }
});

然后,使用一些switch 语句来指导程序的流程。

续:上次我在 Netbeans 中使用 JTabbedPane 时,我所要做的就是添加一个新选项卡并为其构建 GUI。如果您遇到此问题,您可能需要查看 卡片布局

如果您浏览开发屏幕右侧的选项卡,您应该会看到事件列表。您需要做的就是从该列表中选择适当的事件,Netbeans 将为您做这件事。另一方面,您可以使用文本编辑器(WordPad、NotePad++ 等)打开 .java 文件(虽然不在 netbeans 中打开),修改您想要的代码并保存它。当您通过 netbeans 打开文件时,您应该看到您的更改也已加载。

According to here, you can do something like this:

// Create the tabbed pane
JTabbedPane pane = new JTabbedPane();

// Add tabs...; see Adding a Tab to a JTabbedPane Container

// Register a change listener
pane.addChangeListener(new ChangeListener() {
    // This method is called whenever the selected tab changes
    public void stateChanged(ChangeEvent evt) {
        JTabbedPane pane = (JTabbedPane)evt.getSource();

        // Get current tab
        int sel = pane.getSelectedIndex();
    }
});

Then, use some switch statement to direct the flow of the program.

Continuation: Last time I used a JTabbedPane in Netbeans, all that I had to do was to add a new tab and simply build the gui for it. If you are having trouble with this, you might want to take a look at the Card Layout.

If you go through the tabs on the right hand side of your development screen, you should come accross a list of events. What you need to do is to select the appropriate event from that list and Netbeans will do it for you. On the other hand, you can open the .java file (while not open in netbeans) with a text editor (WordPad, NotePad++, etc) modofiy the code you want and save it. When you will open the file back through netbeans, you should see that your changes have been loaded as well.

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