Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9156933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:53:23+00:00 2026-06-17T12:53:23+00:00

So I want to put a button in a JPanel , but I want

  • 0

So I want to put a button in a JPanel, but I want to keep it invisible/hidden unless the mouse pointer hovers over it. At this point, the button should be made visible, react to clicks and so on. When the mouse leaves the area, it should be hidden again.

I tried adding a MouseListener to my JButton and use setVisible(), but when I hide the button (setVisible(false)), then the listener doesn’t work anymore – the application behaves as if the button is not there at all.

What’s the correct way to implement this behavior?

Edit: I am using an absolute layout (setLayout(null)) and I am manually placing my component using setBounds(x, y, width, height).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:53:24+00:00Added an answer on June 17, 2026 at 12:53 pm

    Use icons to reveal (colored) or hide (transparent) the button respectively.

    enter image description here

    import java.awt.*;
    import java.awt.image.BufferedImage;
    import javax.swing.*;
    
    class InvisiButton {
    
        public static void main(String[] args) {
            Runnable r = new Runnable() {
    
                @Override
                public void run() {
                    int size = 30;
                    JPanel gui = new JPanel(new GridLayout(4,10,4,4));
                    for (int ii=0; ii<40; ii++) {
                        JButton b = new JButton();
                        b.setContentAreaFilled(false);
                        b.setIcon(new ImageIcon(
                            new BufferedImage(size,size,BufferedImage.TYPE_INT_RGB)));
                        b.setRolloverIcon(new ImageIcon(
                            new BufferedImage(size,size,BufferedImage.TYPE_INT_ARGB)));
                        b.setBorder(null);
                        gui.add(b);
                    }
    
                    JOptionPane.showMessageDialog(null, gui);
                }
            };
            // Swing GUIs should be created and updated on the EDT
            // http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html
            SwingUtilities.invokeLater(r);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to put an image on a button, but I want part of
I want to put a button as the text of an @ActionLink() but I
I want to put a button on top of webview. For this I've defined
I want to put like button of facebook in my website, I use this
I put a button on view and want to call this view from another
I want put a button on android edittextpreference. I create a custom editextpreference: public
i want to put Go button in android appliation softkeyboard for search and other
Problem: I want to put Twitter Share Button in my Google Map InfoWindow. I
I have 3 buttons Docked to left but I want to put them in
I want to put a button in my android application. When user taps the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.