How do I get the netbeans drag and drop widget to see if it is a render inside the netbeans design viewport or a running application?

How do I get the netbeans drag and drop widget to see if it will show up inside the netbeans design viewport or the running application?

I am trying to do some kind of custom rendering. I think it has something to do with the root container.

0


source to share


3 answers


Try java.beans.Beans.isDesignTime () .



0


source


This is a different 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 that



 Beans.isDesignTime() 

      

it's better

0


source


Testing

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 - it's incredible.

0


source







All Articles