I created a button with JTextPane inside. When I added JTextPane to the JButton I cant click on the button. When I remove JTextPane I can click on the button. Somebody know how to fix this problem?
public class BtnOrderFefcoStyle extends JButton {
private final static String NAME_FONT = "ARIAL";
private final static boolean IS_BOLD = true;
private final static int SIZE_FONT = 18;
private final static Color NAVY_COLOR = new Color(0 , 51 , 102)
private final static int BUTTON_WIDTH = 122;
private final static int BUTTON_HEIGHT = 64;
private final static int BORDER_THICKNESS = 2;
private int posX , posY;
public BtnOrderFefcoStyle(int pos_x , int pos_y)
{
super() ;
this.posX = pos_x;
this.posY= pos_y;
setOpaque(false);
setBorderPainted(false);
setContentAreaFilled(false);
setFocusable(false);
setEnabled(true);
setBorder(null);
setBounds(pos_x, pos_y, BUTTON_WIDTH, BUTTON_HEIGHT);
setForeground(Color.WHITE);
JTextPane nameBtn = new JTextPane();
nameBtn.setEditable(false);
nameBtn.setText("ADD TO LIST");
nameBtn.setAutoscrolls(true);
nameBtn.setEnabled(false);
nameBtn.setOpaque(false);
SimpleAttributeSet attribs = new SimpleAttributeSet();
StyleConstants.setAlignment(attribs, StyleConstants.ALIGN_CENTER);
StyleConstants.setFontFamily(attribs, NAME_FONT);
StyleConstants.setBold(attribs, IS_BOLD);
StyleConstants.setFontSize(attribs, SIZE_FONT);
nameBtn.setParagraphAttributes(attribs, true);
nameBtn.setCaretPosition(1);
nameBtn.setParagraphAttributes(attribs, true);
nameBtn.setDisabledTextColor(NAVY_COLOR);
//nameBtn.setBackground(new Color(153 , 153, 153));
nameBtn.setSize(BUTTON_WIDTH - 2 * BORDER_THICKNESS , BUTTON_HEIGHT - 2 * BORDER_THICKNESS);
//nameBtn.setForeground(NAVY_COLOR);
add(nameBtn);
}
@Override
protected void paintComponent(Graphics g)
{
// TODO Auto-generated method stub
super.paintComponent(g);
g.setColor(Color.WHITE);
g.fillRect(0 , 0 , BUTTON_WIDTH, BUTTON_HEIGHT);
g.setColor(Color.GRAY);
g.fillRect(BORDER_THICKNESS , BORDER_THICKNESS , BUTTON_WIDTH - 2 * BORDER_THICKNESS , BUTTON_HEIGHT - 2 * BORDER_THICKNESS );
}
}