[SOLVED] Switch button state

Discuss here any questions about the WebLaF library.
Bugs can be posted directly to GitHub issues tracker.

[SOLVED] Switch button state

Postby NeDolM » Wed Sep 16, 2015 12:25 am

Hi there

I just dont understand how i can get the status of a Switch button.

the ON| OFF switch button doesn't seem to have enough documentation on it about how i can get the switch status of it or set it to a specific state before showing on screen.

I thought it would be as simple as SwitchBut.getSelected and SwitchBut.setSelected...


None of the example show anything about how to get returns from components.
can anyone point lay down some example code on how to return values from Switch buttons etc...

---

I'm trying to implement this into an existing application so it's not possible to start from scratch using a whole other way of retrieving and storing button/component states.


thanks in advance
NeDolM
 
Posts: 3
Joined: Wed Sep 16, 2015 12:08 am

Re: Switch button state

Postby mgarin » Wed Sep 16, 2015 3:23 am

If you mean WebSwitch componenent - it is exactly isSelected/setSelected methods which retrieve/set the switch state. If you don't see them there - you are probably using older version or I misunderstood which component you are trying to use there.

Documentation right now is mostly limited to a few wiki articles on most complicated things and JavaDoc in the WebLaF sources for everything else. Second one right now is the most reliable source of information as I try to describe every little thing in the code to make it convenient and since the code changes a lot and sometimes wiki articles might get outdated.

You can always look at the source code on GitHub:
https://github.com/mgarin/weblaf/blob/m ... witch.java
or by attaching sources to your IDE project.

Also you can always ask any questions here, on GitHub or by directly mailing me :)

There will be a huge v1.29 update later on which will introduce a lot of new stuff and along with it I am planning to release much more wiki articles. Ideally I want to have at least one on every single component presented in the library.
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg

Re: Switch button state

Postby NeDolM » Wed Sep 16, 2015 12:10 pm

Thank you very much for the fast and detailed reply !

I totally made a mistake in my post. i meant I want to retrieve whether the switch is ON or OFF


example I want to start the switch on the ON status by default ( set the status)
and
example I want to retrieve if the switch if toggled to ON or OFF ( get status)


Code: Select all
private void Switch_AlwaysOnTopActionPerformed(ActionEvent evt) {
if  (this.the_switch.isON()) {
 ....  }
 }


Something like that to detect if it's ticked to the ON status or the OFF status
NeDolM
 
Posts: 3
Joined: Wed Sep 16, 2015 12:08 am

Re: Switch button state

Postby mgarin » Wed Sep 16, 2015 3:23 pm

I didn't really want to make methods point to specific states (like ON or OFF) because you can always replace the switch elements to whatever you like, for example:

Code: Select all
final WebSwitch webSwitch = new WebSwitch ();

final WebLabel leftComponent = new WebLabel ( "Left" );
leftComponent.setMargin ( 4, 6, 4, 2 );
webSwitch.setLeftComponent ( leftComponent );

final WebLabel rightComponent = new WebLabel ( "Right" );
rightComponent.setMargin ( 4, 2, 4, 6 );
webSwitch.setRightComponent ( rightComponent );

In that case those methods will just be wrong, that is why you have selected = true/false instead of state.
When selected = true - you have left component visible, when selected = false - you see the right one.
I believe it is not too hard to remember and use :)
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg

Re: Switch button state

Postby NeDolM » Wed Sep 16, 2015 4:23 pm

Oh my god how could I of missed this *epic facepalm* :lol: well that's pretty embarrassing.
But I guess it's obvious i'm new to java ( started 2 months ago )

My apologies lol Problem is pretty much solved!
Hope it might help some other noob like me, although this place seems like it's all Java professionals.

Thanks for your help!
NeDolM
 
Posts: 3
Joined: Wed Sep 16, 2015 12:08 am

Re: Switch button state

Postby mgarin » Wed Sep 16, 2015 8:11 pm

Always welcome :)
I'll mark this topic as solved.
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg


Return to Questions

Who is online

Users browsing this forum: No registered users and 1 guest

cron