【发布时间】:2014-09-25 11:22:30
【问题描述】:
当在 ExplorerWindow 中按下按钮时,我一直在尝试调用在 EditorWindow 中显示框架的方法。
有 3 个模块:
包含此接口的AppEditorAPI
package org.app.AppEditorAPI;
public interface Displayer {
public void Display();
}
包含 EditorTopComponent 的 AppEditor
@ServiceProvider(service=Displayer.class)
public final class EditorTopComponent extends TopComponent implements Displayer{
private JDesktopPane jdpDesktop=null;
private int openFrameCount = 0;
...
protected void createFrame() {
MyInternalFrame frame = new MyInternalFrame();
frame.setVisible(true);
jdpDesktop.add(frame);
try {
frame.setSelected(true);
} catch (java.beans.PropertyVetoException e) {
}
}
class MyInternalFrame extends JInternalFrame {
int xPosition = 30, yPosition = 30;
public MyInternalFrame() {
super("IFrame #" + (++openFrameCount), true, // resizable
true, // closable
true, // maximizable
true);// iconifiable
setSize(300, 300);
setLocation(xPosition / openFrameCount, yPosition / openFrameCount);
// Add some content:
add(new JLabel("hello IFrame #" + (openFrameCount)));
}
}
public void Display(){
jdpDesktop = new JDesktopPane();
createFrame(); // Create first window
createFrame(); // Create second window
createFrame(); // Create third window
//Add the JDesktop to the TopComponent
add(jdpDesktop);
}
}
以及包含 ExplorerTopComponent 的 AppExplorer
public final class ExplorerTopComponent extends TopComponent {
...
private void initComponents() {
B_Display = new javax.swing.JButton();
..
}
private void B_DisplayActionPerformed(java.awt.event.ActionEvent evt) {
Displayer D = Lookup.getDefault().lookup(Displayer.class);
D.Display();
}
...
}
以下是项目 zip 文件的链接。
http://dl.free.fr/k2Z6DRLrW
http://www.fileswap.com/dl/lCeFPcUfbg/
做了一些测试之后。我发现我无法更改(添加、删除或编辑)EditorTopComponent 的变量或属性。
就像在这种情况下,这两行;
public void Display(){
jdpDesktop = new JDesktopPane();
...
add(jdpDesktop);
}
没有按应有的方式执行,这就是为什么在执行之后,EditorTopComponent.jdpDesktop 仍然等于 null 并且没有添加到 EditorTopComponent。
知道我想做什么,有人可以指导我走上正确的道路吗?
【问题讨论】:
-
贴出相关代码
-
我怀疑这样的工作方式,但这里是代码审查,要求移动(标记你的问题),祝你好运
-
感谢大家的快速回复。
-
@Robert,代码有点长,要不要在评论区发一下?
-
@Robert 带了我一段时间,但我已经按照你的要求添加了 sn-p。
标签: java swing netbeans frame netbeans-platform