【发布时间】:2013-05-23 00:16:21
【问题描述】:
我有一堂课:public class GraphEditorPane extends JGraph
我正在使用这个“GraphEditorPane”,如下所示:
public JScrollPane getGraphPaneScrollPane() {
if (graphPaneScrollPane == null) {
graphPaneScrollPane = new JScrollPane();
//graphPaneScrollPane.setViewportView(getGraphEditorPane());
graphPaneScrollPane.setViewportView(getGraphEditorPane());
}
return graphPaneScrollPane;
}
public GraphEditorPane getGraphEditorPane() {
graphEditorPane = new GraphEditorPane(); }
我正在使用此“GraphEditorPane”在其上绘制图表。现在我的问题是 - 有什么方法可以将此 JGraph 转换为 Glass Pane,以便我的 'GraphEditorPane' 是透明的并且我仍然可以在它上面绘制?
【问题讨论】:
-
玻璃窗格只是一个
Component。只要JGraph从Component扩展(直接或间接)应该能够将其设置为根窗格玻璃窗格。一个玻璃窗格将在根窗格的内容上绘制,这意味着除非您已经直接在JGraph组件上绘制(即覆盖paintComponent方法或直接向其添加组件),否则不会再绘制其他内容它。 -
以及如何将其设置为根窗格玻璃窗格?据我所知,根窗格玻璃窗格是一个完全不同的组件,对吧?
-
我想在 JGraph 组件上作画
-
JRootPane#setGlassPane设置您自己的(请记住,除非组件是透明的,否则它将覆盖其他所有内容)。如果您以这种方式使用玻璃窗格,它将出现在其他所有内容的顶部,除非您直接在其上绘画或在其上添加组件。您可以考虑改用JLayerdPane -
JLayerdPane 用于不同的目的,我不想使用它。我只希望我的滚动窗格是透明的或作为玻璃窗格,这样我就可以将 2 个滚动窗格相互叠加,使其中一个透明,以便在下面的窗格中看到图像和文本,并在顶部窗格上绘制图形也是。这似乎有点令人费解,但这是它应该工作的方式。
标签: java swing glasspane jgraph