Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Does javax.swing.JToggleButton even lift ??

  1. #1
    Member
    Join Date
    Aug 2013
    Posts
    37
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Does javax.swing.JToggleButton even lift ??

    So, i needed a toggle button, that could do a simple things : be able to set ToggleOn or ToggleOff icons, to have a simple event listeners, like if(toggleOn) {do these things} and if(toggleOff) {do these things}. Now, in reality, JToggleButton doesnt have any of toggling functionality by default, it is 1:1 to a simple JButton ... *moderated*


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Does javax.swing.JToggleButton even lift ??

    Hmmm. Not sure if this a real question or a rant with little/no purpose other than to vent. I expected you assumed some functionality of JToggleButton that it doesn't have, but you could have determined that on the API page.

    Edit: And here is a simple example of how to use it.

    You can program a JButton to do what you've described fairly easily.

  3. #3
    Member
    Join Date
    Aug 2013
    Posts
    37
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Does javax.swing.JToggleButton even lift ??

    Yes, i can do it myself, but i noticed, that there is jtogglebutton too, and i expected it to have things like "myJToggleButton.setSelectedIcon(new ImageIcon("images/picture.png"));", just for toggle on/off icons, and "private void myToggleButtonToggleOnPerformed(java.awt.event.Act ionEvent evt);", "private void myToggleButtonToggleOffPerformed(java.awt.event.Ac tionEvent evt);".

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Does javax.swing.JToggleButton even lift ??

    setSelectedIcon is inherited from the Abstractbutton class, says so right there in the API. What problem do you have using it?

  5. #5
    Member
    Join Date
    Aug 2013
    Posts
    37
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Does javax.swing.JToggleButton even lift ??

    setSelectedIcon is not what i needed (or just a wrong name choosen by devs), i have made my own real toggle buttons. I have a few more questions, i did not google about them yet, but maybe you know the answers.

    (it's optional, i dont have to do this, it would be just additional feature) in my program i'm adding and removing buttons, i know i can set icon on button by "myJButton.setIcon(ImageIcon icon)", is there an easy way to add appearance animation on my button by code, like transparency going from 100% to 0 % ? Cause as far as i now, in gif you can set only one transparrent color, and it wouldnt be high quality animation, and i dont know, if java supports things like animated png (apng), and if it does, i dont know, if apng animation could be played once every time when button appears - i have jpanel panel, i have jbutton button, and i do things like "panel.add(button, 0); panel.repaint()" and "panel.remove(button); panel.repaint();".

  6. #6
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Does javax.swing.JToggleButton even lift ??

    Quote Originally Posted by startas View Post
    i expected it to have things like "myJToggleButton.setSelectedIcon(new ImageIcon
    Quote Originally Posted by startas View Post
    setSelectedIcon is not what i needed
    Make up my mind what you want

    Quote Originally Posted by startas View Post
    if java supports things like animated png (apng), and if it does, i dont know, if apng animation could be played once every time when button appears
    Try it and see

  7. #7
    Member
    Join Date
    Aug 2013
    Posts
    37
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Does javax.swing.JToggleButton even lift ??

    I will try it later, and please read everything, not just what you want.

Similar Threads

  1. trouble with selectAll() method of javax.swing.JTextField
    By Daddyspike in forum AWT / Java Swing
    Replies: 0
    Last Post: April 27th, 2013, 05:40 PM
  2. What's the difference between "import.javax.swing*" and JFrame inheritance
    By Johnny Bravo in forum Object Oriented Programming
    Replies: 5
    Last Post: August 14th, 2012, 09:28 AM
  3. JToggleButton's icon won't show up when pressed!
    By andreiutz10 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 30th, 2011, 05:03 AM
  4. Replies: 3
    Last Post: June 11th, 2011, 02:40 PM
  5. [SOLVED] [Problem] imports javax.swing problem
    By Brollie in forum AWT / Java Swing
    Replies: 8
    Last Post: July 5th, 2009, 07:59 AM