【发布时间】:2016-06-28 14:46:48
【问题描述】:
我们在 Swing 应用程序中使用 HTML 来绘制表格
String html = generateHtml();
this.textPane = new JTextPane();
HTMLEditorKit kit = new HTMLEditorKit();
textPane.setEditorKit(kit);
StyleSheet styleSheet = kit.getStyleSheet();
styleSheet.addRule("th, td {width: 50px; text-align: center;}");
Document doc = kit.createDefaultDocument();
textPane.setDocument(doc);
textPane.setContentType("text/html");
textPane.setText(html);
textPane.setEditable(false);
textPane.setBackground(null);
textPane.setBorder(null);
textPane.putClientProperty(JTextPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
this.add(textPane);
我希望能够在其中一个表格单元格内单击,以调用 java 类回调,也许是通过 javascript?或任何其他选择?
例如,单击将调用 java 方法执行某些工作的表格单元格,并打开一些对话框窗口。
也许这可以通过javascript来回调java?还是直接从html转java?
我知道有 3rd 方库,例如 JxBrowser,像 example,但是,我们首先查看是否有办法通过使用内置组件来做到这一点,而无需将 3rd 方库添加到分布式应用程序中。
【问题讨论】:
-
这听起来像是
JTable的工作.. -
@Andrew Thompson 是的,谢谢,大多数应用程序确实使用 JTables,但是在一个特定的地方,出于内部特定原因,选择了 html。
标签: javascript java html swing callback