我点击按钮时如何知道哪个“面板”是可见的?

huangapple go评论68阅读模式
英文:

How Can I Know Which "Panel" Is Visible When I Click A Button?

问题

以下是翻译好的部分:

这是程序的外观(Gifs)

所以我不想为我的程序使用大量的帧。我有许多表格要展示。所以我做了一些按钮。当我点击按钮时,它会关闭其他表格,只显示一个表格。当我点击其他按钮时,它会关闭旧的表格并显示新的表格。代码看起来像这样:

btn_1.addMouseListener(new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent e) {
        table1_panel.setVisible(false);
        table2_panel.setVisible(false);
        table3_panel.setVisible(false);
        table4_panel.setVisible(false);
        table5_panel.setVisible(true);
    }
});

所以它会关闭其他面板并打开一个面板。但是,当我点击“Detayları Görüntüle”按钮时,我希望打开一个显示所选行详细信息的窗口。但是当我点击时,我需要知道哪个表格是可见的,以便为每个其他表格执行不同的代码。所以我需要类似这样的东西:

if (table5_panel.isVisible()) {
    // 在这里执行相应的代码
}

但是如你所知,table5_panel.setVisible(true)不是布尔值,所以它不起作用。我需要什么样的代码来检查哪个表格是可见的?
1: https://gfycat.com/reasonablehotivorygull

英文:

This is how the program looks like (Gifs)

So i dont want to use tons of frames for my programs. I have many tables to show. So i made some buttons. When i click the tubbon ,it close other tables and show only one table. And when i click other button ,it close old one and show the new one. Code looks like this:

btn_1.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					table1_panel.setVisible(false);
					table2_panel.setVisible(false);
					table3_panel.setVisible(false);
					table4_panel.setVisible(false);
					table5_panel.setVisible(true);
				}
			});

So it close other panels and open only one panel. But i also need when i click the button "Detayları Görüntüle" , i want to open a frame with details of selected row. But when i click ,i need to know what table is visible so i can do different codes for every other tables. So i need something like this :

if(table5_panel.setVisible(true);){
}

But as you know it is not boolean so it does not works. What code i need to check which table is visible ?

答案1

得分: 0

使用 CardLayout 来包含你的面板。

然后你就不需要隐藏/显示面板了。UI 会为你完成这项工作。

> 我想要打开一个包含所选行详细信息的窗口。

处理表格的按钮应该放在每个面板上,而不是菜单上。

每个表格显示的详细信息都不同,所以逻辑应该与面板相关,以便可以为每个表格进行定制。

英文:

Use a CardLayout to contain your panels.

Then you don't need to hide/show panels. The UI does the work for you.

> i want to open a frame with details of selected row.

The button to process the table belongs on each panel, not on the menu.

The details displayed are different for each table, so the logic belongs with the panel so it can be customized for each table.

huangapple
  • 本文由 发表于 2020年8月14日 06:34:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/63404106.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定