【问题标题】:How can I add a JDesktopPane to an EditorTopComponent, from an ExplorerTopComponent?如何从 ExplorerTopComponent 将 JDesktopPane 添加到 EditorTopComponent?
【发布时间】: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


【解决方案1】:

终于,'让它工作了......看看当你避免阅读书籍时会发生什么:P

如果有人遇到同样的问题,我会发布解决方案。

正如我在编辑我的问题时提到的,知道不允许通过查找进行修改,您可以使用可以在查找中修改的 InstanceContent 变量,或者使用 WindowManager 安装 EditorTopComponent 并调用 Display( ) 方法。

祝你好运

【讨论】:

    猜你喜欢
    • 2014-05-17
    • 1970-01-01
    • 2011-11-23
    • 2012-09-22
    • 2011-10-15
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 2010-12-01
    相关资源
    最近更新 更多