0

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.

hawkeye
  • 34,745
  • 30
  • 150
  • 304

3 Answers3

0

Try java.beans.Beans.isDesignTime().

Dave Ray
  • 39,616
  • 7
  • 83
  • 82
0

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

hawkeye
  • 34,745
  • 30
  • 150
  • 304
0

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.

hawkeye
  • 34,745
  • 30
  • 150
  • 304