Note that there are some explanatory texts on larger screens.

plurals
  1. POJTextArea swallowing JButton action listener Java
    primarykey
    data
    text
    <p>I have an action listener on a JButton and a JTextArea in the button. However when I click the button the text area swallows the event, and nothing happens to the button.</p> <p>How can I click through the area?</p> <p>Thank you</p> <p>Button code</p> <pre><code>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(); } </code></pre> <p>GUI Class code</p> <pre><code>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); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload