Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

AbstractAction with toggle state

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone know an easy way to extend custom AbstractAction extending class with toggle state - the custom implementation is added in a JToolbar and I need it to be shown toggled/untoggled.
Thanks in advance.
 
Saloon Keeper
Posts: 12295
259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean like a checkbox? Why don't you just add a JCheckBox to the JToolBar?

[edit]

If you actually want a JButton that has two states, you can simply add a JToggleButton to the JToolBar.
 
vladislav peichev
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not like JCheckBox but like JToggleButton. My application uses customized AbstractAction with some additional functionality e.g. enabling or disabling depending on condition so I cannot use the standard JToggleButton. I want my AbstractAction extension to be displayed toggled/untoggled.
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another alternative is to use a JToggleButton (you can pass the Action instance to its constructor). I suppose JToggleButton would look better on a toolbar.
 
Martin Vashko
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

vladislav peichev wrote:Not like JCheckBox but like JToggleButton. My application uses customized AbstractAction with some additional functionality e.g. enabling or disabling depending on condition so I cannot use the standard JToggleButton. I want my AbstractAction extension to be displayed toggled/untoggled.


Of course you can use JToggleButton. In your child of AbstractAction, you'll just check the action's Selected state. That is, don't mess with the selection state yourself, let the JToggleButton manage it. Just test the state in actionPerformed and enable/disable the other controls accordingly.
 
Stephan van Hulst
Saloon Keeper
Posts: 12295
259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
lightning.png
[Thumbnail for lightning.png]
Place in img folder under classpath
 
Your mother is a hamster and your father smells of tiny ads!
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic