Search code examples
javauser-interfacejbutton

Why can't I add a JHoverButton to my GUI?


I built a JHoverButton class that looks as such:

package javabeanslab;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class JHoverButton extends JButton implements MouseListener {

public JHoverButton(){
    super();
    initialize();
}

public JHoverButton(String text){
    super(text);
    initialize();
}

public JHoverButton(String text, Icon icon){
    super(text, icon);
    initialize();
}

public void setEnabled(boolean enabled){
    super.setEnabled(enabled);
    if(enabled){
        if(isBorderPainted()){
            setBorderPainted(false);
            repaint();
        }
    }
}

private void initialize(){
    setBorderPainted(false);
    addMouseListener(this);
}

@Override
public void mouseClicked(MouseEvent me) {

}

@Override
public void mousePressed(MouseEvent me) {

}

@Override
public void mouseReleased(MouseEvent me) {

}

@Override
public void mouseEntered(MouseEvent me) {
    if(!isBorderPainted() && isEnabled()){
        setBorderPainted(true);
        repaint();
    }
}

@Override
public void mouseExited(MouseEvent me) {
    if(isBorderPainted()){
        setBorderPainted(false);
        repaint();
    }
}

}

Now when I go to the GUI builder in Netbeans, I click on "Choose Bean" and then I declare the path as javabeanslab.JHoverButton to add the button in to the GUI but I get this error that pops up:

What am I doing wrong?


Solution

  • The problem is that, to use a class in the GUI Builder, it has to be already compiled, because the tool looks for a .class file to load the properties of your widget.