javaswingnetbeansballoon-tip

NetBeans GUI editor, can't construct the object


Its hard to explain it for me and even harder in english... I have this component constructor

Balonik = new BalloonTip(textfield, new JLabel("Do not devide by 0!"),
            new RoundedBalloonStyle(5,5,Color.WHITE, Color.BLACK), 
            BalloonTip.Orientation.RIGHT_BELOW, 
            BalloonTip.AttachLocation.ALIGNED, 
            15, 
            15, 
            false
    );

and I put this code in frame constructor in netbeans jFrame project

public oknoo() {

    initComponents();

    Balonik = new BalloonTip(textfield, new JLabel("Do not devide by 0!"),
            new RoundedBalloonStyle(5,5,Color.WHITE, Color.BLACK), 
            BalloonTip.Orientation.RIGHT_BELOW, 
            BalloonTip.AttachLocation.ALIGNED, 
            15, 
            15, 
            false
    );
}

it is compiling however the BalloonTip doesnt show up.

The funny thing is that when Ive exported project to eclipse(where I could edit the initComponent() function), and left this component constructor in initComponent() function then it has worked. so the same code works in initComponent() function and not working within the constructor....

I dont understand. And Im asking because I cant just fix this problem in Eclipse and export back to netBeans.... because of this ...

/**
 * 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.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">                          
private void initComponents() {

Solution

  • BalloonTip does not show up because it is created after pack() is called. You will need to call pack() on the constructor after initComponents(), not on that method.

    public oknoo() {
    
        initComponents();
    
        Balonik = new BalloonTip(textfield, new JLabel("Do not devide by 0!"),
                new RoundedBalloonStyle(5,5,Color.WHITE, Color.BLACK), 
                BalloonTip.Orientation.RIGHT_BELOW, 
                BalloonTip.AttachLocation.ALIGNED, 
                15, 
                15, 
                false
        );
    
        pack();
    }
    

    But pack() should not be called on initComponents(). On Code properties of JFrame (right click on frame on GUI builder -> properties), select No Resize Code for Form Size Policy.