I have 2 images for a JComponent, one of an unpressed button, and one of a pressed button. When I click the button, I want the image to change for the pressed one, but only while I am clicking. Which means whenever I release the mouse button, the image goes back to the unepressed button.
How can I do this?
Using a JButton, set the standard and pressed icons.
Related
I need the ability for a user to press and set an ListView item's checkbox independently of clicking on the item. If they press on the checkbox I will add/remove the checkmark and take some action. If they press on the item text I can take another action.
I can do this with a ListBox no problem with built in functionality. I can't figure out how to do it with a ListView. How is it done?
I can put the following code in the ListView1ItemClickEx to know when the user is clicking on the image. Maybe I can just change the image to a checkmark?
if (ItemObject->Name == "I") {
ShowMessage("Item Image clicked");
}
But I don't know how to change that particular items image (e.g. I could just toggle between a checkmark image and an unchecked image) at runtime.
The picture below is for clarity. Clicking anywhere in the red box will change the items checkbox. For the ListBox clicking anywhere in the blue box will fire the OnClick event and not change the checkbox. I want that same behavior in the ListView.
Ok, Remy answered this related question and it helped me solve this issue. Now I can make the ListView have a checkbox that functions like that of the ListBox. I do it by toggling the item image whenever the user presses (or clicks on) the image area of an item.
When the user clicks an items image I trap it (per Remy's code in the ListView1ItemClickEx event) and toggle it from 0->1 or 1->0 in a vector at reference ItemIndex (e.g. myVector[ItemIndex] = 0) and then I completely rebuild the ListView (clear it and build from scratch).
I thought I'd have to remember where in the list I had scrolled down to and after refreshing the ListView I'd have to scroll to that point in code - but, that isn't the case. I don't know why but after the refresh I'm still at the point in the list where I clicked an item image. It makes it work and feel exactly like a check box.
It works great in iOS, Android, and Windows.
p.s. I forgot to mention that you need to treat any Header's like they are items in your vector that keeps up with each items' image (0 or 1). Otherwise adding headers gets you out of sync and clicking an item's image will toggle some other item's image.
I have an NSButton created in Interface Builder with the style "Round Textured". When the button is disabled, the text colour does not go grey as you would expect. Oddly enough when the button contains an image instead of text, the image does go grey, as seen in the below screenshot (top buttons are enabled, bottom buttons are disabled).
How can I get the text to go grey when the button is disabled?
Update: So it gets weirder: the view containing the button is shown in a popover and every second time the view is shown the button is greyed out.
It seems, at least in Yosemite, as long as you set button.wantsLayer = YES on the button view, that it then works. Go figure.
I have a one UIButton with a value, when you start the app, the TitleLabel of the button has been Hidden “call” (button.titleLabel.hidden=YES).
I have connected the button with a one IBAction (TouchDown) for when the user press the button appear the value / “call” (button.titleLabel.hidden=NO) and disappear with one NSTimer in 3 seconds after call (button.titleLabel.hidden=YES)
If you press one time the button is work good, (appear and disappear) but when you press without release the button and you move outside area and return inside area of the button the Value of Title appear again. Not work (button.titleLabel.hidden=YES)
I tested with another IBAction (Drag enter, Drag exit) in parallel to force the (button.titleLabel.hidden=YES) but the Value of the Title appear. Also take out the Timer but not working…
Please could you help me.
Thanks
Edit.
you must have created the button via Storyboard/XIB. Please check the sent events by right-clicking the button and set it to touch down. This should resolve the problem. :)
I want to change button on same button click how i can do that in blackberry. i used frame layout in android for overlay two field one after above so how i can change field on same click in blackberry?
like e.g i want to kept two buttons on same position when i click btn1 btn2 should display and when i click btn2 btn1 should display
Hay i done with replace method thanks for all of u for reply
i used
vfm.replace(oldField, newField);
to swap
Changing part of the screen in when button clicks in Blackberry //here is the link
I want to show image when button is pressed on main screen in blackberry, How can I do this?
Simply I have a button, when I do press it, the data is loading from xml, and I want to show that data is loading, how can I do this, I have image(having text on it).
Help!
You can add that image in a vertical field manageer and add the vertical field manager to the screen on the button click. that's it..