У меня есть прослушиватель действий на JButton и JTextArea в кнопке. Однако, когда я нажимаю кнопку, область текста проглатывает событие, и ничего не происходит с кнопкой.JTextArea проглатывание JButton action listenener Java
Как я могу щелкнуть по области?
Спасибо
Код кнопки
public class CustomFoodItemButton extends JButton{
public JTextArea buttonTitle;
/**
* Public constructor
* @param title
*/
public CustomFoodItemButton(String title) {
//Set button text by using a text area
buttonTitle = new JTextArea();
buttonTitle.setText(title);
buttonTitle.setFont(new Font("Helvetica Neue", Font.PLAIN, 15));
buttonTitle.setEditable(false);
buttonTitle.setWrapStyleWord(true);
buttonTitle.setLineWrap(true);
buttonTitle.setForeground(Color.white);
buttonTitle.setOpaque(false);
//Add the text to the center of the button
this.setLayout(new BorderLayout());
this.add(buttonTitle,BorderLayout.CENTER);
//Set the name to be the title (to track actions easier)
this.setName(title);
//Clear button so as to show image only
this.setOpaque(false);
this.setContentAreaFilled(false);
this.setBorderPainted(false);
//Set not selected
this.setSelected(false);
//Set image
setImage();
}
код GUI Класс
private void addFoodItemButtons (JPanel panel){
//Iterate over menu items
for (FoodItem item : menuItems) {
//Create a new button based on the item in the array. Set the title to the food name
CustomFoodItemButton button = new CustomFoodItemButton(item.foodName);
//Add action listener
button.addActionListener(this);
}
}
Добавлен код. –
Чтобы лучше помочь, опубликуйте [SSCCE] (http://sscce.org/). –