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?

StackOverflow https://stackoverflow.com/questions/399929

Question

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?

I'm trying to do some custom rendering. I think it has to do with the root container.

Was it helpful?

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top