Results 1 to 11 of 11
Thread: need help making hidden JButton
- 03-12-2011, 03:00 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 4
- Rep Power
- 0
need help making hidden JButton
Hello im new here and i just want to ask how to make an invisible jbutton where you still click it even though it cannot be seen
i already tried
button.setVisible(false);
button.hide();
it makes the button invisible although i cannot click it anymore
hoping for help here and thanks in advanced
cheers
-
What functionality are you trying to achieve? If you just want a clickable location, why not just use a MouseListener?
- 03-12-2011, 03:30 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 4
- Rep Power
- 0
basically i want to make like a hidden button wherein when its clicked another window will pop out
-
Last edited by Fubarable; 03-12-2011 at 03:50 PM.
-
Do you understand what I mean about using a MouseListener? I assume that you don't want a button that can be seen or that even "clicks" but you want a region of the GUI that responds to mouse presses, and a MouseListener can fit that bill. It can be added to any component, it is not seen, it can be coded so that it only responds to clicks in a certain specified region, and in the mousePressed method of the MouseListener, you can put in the code that you otherwise would have placed in your JButton's ActionListener's actionPerformed method. You can learn more about these at the Oracle Swing tutorial: How to Write a Mouse Listener
Last edited by Fubarable; 03-12-2011 at 04:05 PM.
- 03-12-2011, 05:47 PM #6
Member
- Join Date
- Mar 2011
- Posts
- 4
- Rep Power
- 0
Oh ok thanks, one last question, how to do make a certain "region" , it would be too hard if it was just one certain point
-
You're welcome. The easiest way would be to add it to a single component that covers the region of interest. If you can't do this, then you would still add the listener to a single component, but in the mousePressed method, you would only respond if the mouse button coordinates are where you want them to be. So you would get the Mouse location from the MouseEvent object passed into the method's parameter (note that the location is relative to the component that has the listener -- i.e., 0, 0 is at the top left of the component) and use an if block to see if the mouse is where you want it. Give it a try and if you get stuck, come on back with your code, preferably an SSCCE.
- 03-13-2011, 05:34 AM #8
Member
- Join Date
- Mar 2011
- Posts
- 4
- Rep Power
- 0
I finally did it thanks a lot really appreciate your help in helping a beginner like me, I just used if statements to get the part like this one
if(e.getX()>=230 && e.getX()<=580 && e.getY()>=310 && e.getY()<=380){
again thanks for the reply, i can finally move on to the next part XD
-
- 04-10-2012, 11:43 PM #10
Member
- Join Date
- Apr 2012
- Location
- Ireland
- Posts
- 5
- Rep Power
- 0
Re: need help making hidden JButton
Hey,
This seems to be the only post about this and although a mouse listener is a better option I thought I would answer this.
I wanted to make a JButton hidden for my project instead of a mouse listener just to keep my code clean.
If i remember you must implement 5 or 7 mouse listener methods.
My solution is as follows:
In paint I created an image the exact size of my JButton and color of the background JPanel, which for the windows look and feel was:
Hue: 160
Red: 238
Green: 238
Blue: 238
Lum: 224
Sat: 0
This was judged but looks right.
I then used the setIcon method to set this image and setBorder(null) to remove the black border.
JButton is now completely invisible even when clicked and still has functionality.
Hope this helps people I used this to have a sneaky way to enter admin mode in my program.
- 04-11-2012, 03:18 AM #11
Re: need help making hidden JButton
Someone asked a similar question on StackOverflow a long time ago. One suggestion was to extend JButton and override paint() so it does nothing.
Get in the habit of using standard Java naming conventions!
Similar Threads
-
Android Run in Hidden mode
By Blackberrylerner in forum New To JavaReplies: 1Last Post: 03-04-2011, 07:14 PM -
password with hidden characters and 3 attempts
By khay in forum New To JavaReplies: 7Last Post: 12-05-2010, 02:44 PM -
hidden columns in jxtable
By new2java2009 in forum New To JavaReplies: 0Last Post: 09-27-2010, 10:13 PM -
[SELENIUM] Retrieve the value of a hidden input type
By gecko753 in forum Web FrameworksReplies: 1Last Post: 11-04-2009, 03:32 PM -
Hidden Button after paint()
By MuslimCoder in forum New To JavaReplies: 5Last Post: 09-14-2009, 05:52 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks