gpt4 book ai didi

java - 为什么我的 TopComponent 上的 JavaFX 内容消失了?

转载 作者:搜寻专家 更新时间:2023-10-30 21:01:41 24 4
gpt4 key购买 nike

我遇到了一个问题,这可能是由于对 Netbeans 平台 (7.1.2) 或 JavaFX 2 的某些原理缺乏理解造成的。我想添加一个 JFXPanel非常简单的 Scene 到作为 TopComponent 子级的 Swing JPanel。我通过以下代码实现了这一点:

 public accexTopComponent() {
initComponents();
setName(Bundle.CTL_accexTopComponent());
setToolTipText(Bundle.HINT_accexTopComponent());
putClientProperty(TopComponent.PROP_CLOSING_DISABLED, Boolean.TRUE);



//Begin of my code
myFX = new JFXPanel(); //myFX is a static JFXPanel
Platform.runLater(new Runnable() {

@Override
public void run() {

myFX.setScene(new Scene(ButtonBuilder.create().minHeight(40.0).minWidth(40.0).build()));

}
});

jPanel1.add(myFX);



}

编译没有问题,当我第一次显示 TopComponent 时,会显示 JavaFX Button。但是一旦组件被隐藏并再次显示,JavaFX Button 就会消失,而其他子项仍然可见。

为什么 JavaFX 内容消失了?

编辑:

我现在包括整个 TopComponent 的源代码。我想这就是您自己测试所需的全部内容。我没有更改任何其他文件。

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package de.jeed.nbgan.accexplorer;

import java.awt.Color;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.control.ButtonBuilder;
import javafx.scene.text.TextBuilder;
import javafx.scene.web.WebView;
import javafx.scene.web.WebViewBuilder;
import org.netbeans.api.settings.ConvertAsProperties;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.windows.TopComponent;
import org.openide.util.NbBundle.Messages;

/**
* Top component which displays something.
*/
@ConvertAsProperties(dtd = "-//de.jeed.nbgan.accexplorer//accex//EN",
autostore = false)
@TopComponent.Description(preferredID = "accexTopComponent",
//iconBase="SET/PATH/TO/ICON/HERE",
persistenceType = TopComponent.PERSISTENCE_ALWAYS)
@TopComponent.Registration(mode = "explorer", openAtStartup = true)
@ActionID(category = "Window", id = "de.jeed.nbgan.accexplorer.accexTopComponent")
@ActionReference(path = "Menu/Window" /*
* , position = 333
*/)
@TopComponent.OpenActionRegistration(displayName = "#CTL_accexAction",
preferredID = "accexTopComponent")
@Messages({
"CTL_accexAction=accex",
"CTL_accexTopComponent=Konten-Explorer",
"HINT_accexTopComponent=Durchsuchen von Abteilungen und Konten"
})
public final class accexTopComponent extends TopComponent {

static JFXPanel myFX;

public accexTopComponent() {
initComponents();
setName(Bundle.CTL_accexTopComponent());
setToolTipText(Bundle.HINT_accexTopComponent());
putClientProperty(TopComponent.PROP_CLOSING_DISABLED, Boolean.TRUE);
myFX = new JFXPanel();
Platform.runLater(new Runnable() {

@Override
public void run() {

myFX.setScene(new Scene(ButtonBuilder.create().minHeight(40.0).minWidth(40.0).build()));

}
});

jPanel1.add(myFX);


}

/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jPanel1 = new javax.swing.JPanel();

jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
jPanel1.setLayout(new java.awt.GridBagLayout());

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(54, 54, 54)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(153, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(33, 33, 33)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(74, Short.MAX_VALUE))
);
}// </editor-fold>
// Variables declaration - do not modify
private javax.swing.JPanel jPanel1;
// End of variables declaration

@Override
public void componentOpened() {
// TODO add custom code on component opening
}

@Override
public void componentClosed() {
// TODO add custom code on component closing
}

void writeProperties(java.util.Properties p) {
// better to version settings since initial version as advocated at
// http://wiki.apidesign.org/wiki/PropertyFiles
p.setProperty("version", "1.0");
// TODO store your settings
}

void readProperties(java.util.Properties p) {
String version = p.getProperty("version");
// TODO read your settings according to their version
}
}

在我的例子中,这个 TopComponent 是一个名为 AccountExplorer 的组件的一部分,它引用了 JavaFX 并被一个普通的 NB 平台应用程序引用。

最佳答案

试试这个:

Platform.setImplicitExit(false);

关于java - 为什么我的 TopComponent 上的 JavaFX 内容消失了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10618757/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com