- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试为可编辑的 JTable
实现撤消(和重做)功能使用默认组件。 JTable
有一个额外的类来指定其名为 SpecifiedJTable
的属性.
为此,我想捕获双击单元格的时刻(即选择/标记单元格进行编辑的时刻)以将单元格中的信息及其坐标推送到堆栈上。
这应该由 MouseListener
完成……至少这是我的想法。
我试过了(站在我的 SpecifiedJTable
类的构造函数中)
class JTableSpecified extends JTable {
private static final long serialVersionUID = 1L;
private int c; // the currently selected column
private int r; // the currently selected row
public JTableSpecified(String[][] obj, String[] columnNames) {
super(obj, columnNames); // constructs the real table
// makes that you can only select one row at a time
this.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
// makes that columns are not squeezed
this.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
// forbids to rearrange the columns
getTableHeader().setReorderingAllowed(false);
// adds action listener
this.getModel().addTableModelListener(new TableModelListener() {
public void tableChanged(TableModelEvent e) {
r = getSelectedRow();
c = getSelectedColumn();
// get the String at row r and column c
String s = (String) getValueAt(r, c);
if (jobDisplayed) jobSwitch(c, s);
else resSwitch(c, s);
}
});
this.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
System.out.println("test");
}
}
});
}
}
最佳答案
您遇到的问题与使用 mouseClicked()
有关而不是使用 mousePressed()
.在这种情况下,增加点击计数器似乎非常困难,但仍有可能。我需要多次点击和鼠标移动才能将点击计数器增加到 1 以上。您可以在代码中自己尝试。要使计数器超过 1,您需要在鼠标从一个单元格移动到另一个单元格的同时快速按下和释放来使鼠标变得疯狂(或者也许我只是幸运地在单元格之间单击?)。
正如您在这个完全工作的示例中所看到的,使用您的代码,两次鼠标按下,使用 mousePressed()
方法正在被检测到就好了。
public class JTableSpecified extends JTable {
private static final long serialVersionUID = 1L;
public JTableSpecified(String[][] obj, String[] columnNames) {
super(obj, columnNames); // constructs the real table
// makes that you can only select one row at a time
this.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
// makes that columns are not squeezed
this.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
// forbids to rearrange the columns
getTableHeader().setReorderingAllowed(false);
// adds action listener
this.getModel().addTableModelListener(new TableModelListener() {
@Override
public void tableChanged(TableModelEvent e) {
}
});
this.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
if (e.getClickCount() == 2) {
System.out.println("test");
}
System.out.println("e.getClickCount() = " + e.getClickCount());
}
});
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JPanel panel = new JPanel();
panel.add(new JTableSpecified(new String[][]{{"oi", "oi2"}, {"oi3", "oi4"}}, new String[]{"Col1", "Col2"}));
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setContentPane(panel);
f.pack();
f.setVisible(true);
}
});
}
}
mousePressed()
方法?
关于java - JTable 不会监听 Doubleclicks,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11105133/
看这里: 从一个页面显示该元素有双击“dblclick”事件 但是当我尝试从控制台执行它时: 最佳答案 dblclick 不是一种方法,它是一种事件。假设您有一个按钮,并且您想手动触发该事件。你可以这
我正在使用 PropertyGrid 控件来编辑我的应用程序中的一些对象。我正在使用自定义 TypeConverter 和 TypeEditors 以获得更好的用户界面。 我对 bool 属性的自定义
The documentation for the MouseDoubleClick event州 Important DoubleClick events are logically higher-
DoubleClick 交换是否支持 openRTB 协议(protocol)? 最佳答案 Google Ad Exchange 在 HTTP Post 上使用 protobuf,并且有自己的模型。
我正在尝试为可编辑的 JTable 实现撤消(和重做)功能使用默认组件。 JTable有一个额外的类来指定其名为 SpecifiedJTable 的属性. 为此,我想捕获双击单元格的时刻(即选择/标记
是否有 ToolStripStatusLabel DoubleClick曾经工作吗? Private Sub myToolStripStatusLabel_DoubleClick(ByVal send
我有 html 表,里面有 tr 和 td。现在我所有的 Td 都在上不同的课。我想执行操作,就像每当我调用一个函数时,具有特定类的特定 td 自动执行双击功能,并且我传递的一个值将存储在该 td 中
我有一个来自广告网络的广告代码,其结构如下 api_key = X; param1 = Y; param2 = Z; ... 标
是否可以向广告素材的目标网址添加网址参数? 示例: 我在 DFP 广告管理系统 www.mysite.com 中具有目标链接的网站上加载横幅 页面上的 JavaScript 强制 DFP 广告管理系统
我是新来的,我正在尝试做一些理论上简单的事情,但我就是做对了。我需要在点击事件中触发 DCM Floodlight 代码。我遇到的问题是 href 元素中已经包含了一个 Google Analytic
有谁知道如何使用 Google sizeMapping 对象定位页外广告位以转换自适应广告? 我试过使用“页外”作为尺寸,但它不起作用。 var outOfPageMapping = googleta
我正在尝试将以下代码转换为“onClick”事件以添加到 HREF 标记。我的 JavaScript 经验有限,但我知道这是可以做到的。任何形式的指导将不胜感激。 var axel = Math.r
我有一个名为 listView 的 QListView。它是 MainWindow 中唯一的小部件。我想跟踪 listView 上的双击。所以,我这样做了: #include "mainwindow.
我遇到异常: '{0}' is not a Visual or Visual3D. 我发现唯一类似的问题:WPF: System.ArgumentException => {"'{0}' is not
我一直在尝试让 Doubleclick 广告代码加载我的动态内容。我有一个网站,当您向下滚动时,它会加载更多内容,而不必转到下一页、后退一页等。但是,我未能成功加载每 2 到 3 页上的广告。 有人知
我是网站 legiaodosherois.com.br 的所有者,在使用 Google DFP 开始我的第一个付费广告系列后遇到了问题。我所有的广告块都设置为 Adsense 回退,直到两天前我的所有
有没有一种方法可以在控件 DoubleClick 事件中获取鼠标光标的 (x, y) 坐标? 据我所知,位置必须从全局获取: Windows.Forms.Cursor.Position.X、Windo
WPF, Shapes 我有一个自定义 Shape ,并尝试实现 MouseClick和 MouseDoubleClick上面的东西。 通过例如。我需要打开一个关于 MyShape OnClick 的
我在 XAML 中有一个 ListView 控件。 这些项目由一个模板控件定义,该控件在网格内具有一个 TextBlock。 现在我想在双击 TextBlock 时触发一个 Action 。 令我惊讶
我在窗口上有一个带有 DataGrid 的 WPF/MVVM 应用程序。当用户双击 DataGrid 中的一行时,我想调用一个方法。 如何将 DataGrid 的 DblClick 事件绑定(bind
我是一名优秀的程序员,十分优秀!