[英]How do I get my netbeans drag and drop widget to know whether it is rendering inside the netbeans design view window or the running application?
How do I get my netbeans drag and drop widget to know whether it is rendering inside the netbeans design view window or the running application? 如何获取我的netbeans拖放小部件,以了解它是在netbeans设计视图窗口中还是在正在运行的应用程序中进行渲染?
I'm trying to do some custom rendering. 我正在尝试做一些自定义渲染。 I think it has to do with the root container.
我认为这与根容器有关。
This is another method: 这是另一种方法:
Component c = javax.swing.SwingUtilities.getRoot(this);
String className = c.getClass().getCanonicalName();
if (!"org.netbeans.core.windows.view.ui.MainWindow"
.equalsIgnoreCase(className)) {
Although I think the 虽然我认为
Beans.isDesignTime()
method is better 方法更好
Testing the 测试
Beans.isDesignTime()
with the following example 下面的例子
package test;
import java.awt.Graphics;
import java.beans.Beans;
import javax.swing.JLabel;
public class TestLabel extends JLabel {
private static final long serialVersionUID = -2438507032083091628L;
public TestLabel() {
super();
}
public void paint(Graphics g) {
super.paint(g);
if (Beans.isDesignTime())
this.setText("Design Time");
else
this.setText("Production runtime");
}
}
It works - that's quite incredible. 它有效-太不可思议了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.