禁用 JTable 上的弹出菜单
我正在创建一个像这样的带有弹出菜单的表,
JTable table = new Table()
table.addMouseListener( new MouseAdapter()
{
public void mouseReleased(MouseEvent e)
{
if (e.isPopupTrigger())
{
JTable source = (JTable)e.getSource();
int row = source.rowAtPoint( e.getPoint() );
int column = source.columnAtPoint( e.getPoint() );
if (! source.isRowSelected(row))
source.changeSelection(row, column, false, false);
popup.show(e.getComponent(), e.getX(), e.getY());
}
}
});
我希望能够通过调用启用/禁用此菜单,我尝试了以下操作:
table.setEnabled(false),
但菜单仍然弹出。我应该做什么调用?
I am creating a table like this with a popop menu
JTable table = new Table()
table.addMouseListener( new MouseAdapter()
{
public void mouseReleased(MouseEvent e)
{
if (e.isPopupTrigger())
{
JTable source = (JTable)e.getSource();
int row = source.rowAtPoint( e.getPoint() );
int column = source.columnAtPoint( e.getPoint() );
if (! source.isRowSelected(row))
source.changeSelection(row, column, false, false);
popup.show(e.getComponent(), e.getX(), e.getY());
}
}
});
I want to be able to enable/disable this menu with a call, I tried this:
table.setEnabled(false)
but the menu still pops up.. What call should I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在创建名为 tableMenuEnabled 的表的类中使用布尔值。您应该能够在计划调用 table.setEnabled(false) 的地方将 tableMenuEnabled 设置为 true 或 false。从那里你的代码将更改为:
You could have a boolean inside of the class that is creating the table called tableMenuEnabled. You should be able to set tableMenuEnabled to true or false where you were planning on calling table.setEnabled(false). From there your code would change to:
好吧,您可能必须将其作为侦听器删除。因此,将其保留为类中的成员变量,如下所示:
您的其他代码将变为:
然后,您的调用将如下所示:
另外,要将其添加回来,您可以具有以下内容:
Well, you'd probably have to remove it as a listener. So, keep it as a member variable in your class, like this:
your other code would become:
then, your call would look like:
also, to add it back in, you could have the following: