Getting rid of pressed effect in JavaFx toggle Button - javafx

How can I get rid of the pressed effect of javafx toggle button? Essentially, I want the look and feel of the button to be the same except the background image.

In your CSS file, you can do
.toggle-button:armed {
-fx-color: -fx-base ;
}
You might also want to remove the hover effect:
.toggle-button:armed, .toggle-button:hover {
-fx-color: -fx-base ;
}

Related

How do I switch the image files I want to see in a JavaFXML Button?

I am trying to toggle a button between two states. One state is to display an
image of a red circle, the other state being an image of a blue circle. When the user clicks the button it should toggle between the states. I have set
style in my css to accommodate the button:
#button-debit {
-fx-background-image: url("images/redButton.jpg");
}
#button-credit {
-fx-background-image: url("images/blueButton.png");
}
To see if this works I have tried just to transform from red to blue by doing this:
#FXML
private void handledborcrBtn() {
dborcrBtn.setId("button-credit");
}
However the result is not as expected. The red button image stays in place with the blue one underneath it, but the blue image is split up into several parts.
I think I remember a 'repaint' method from javax Swing but there seems to be more complicated with JavaFXML and I'm having trouble getting this to work properly.
Try it with the ToogleBotton
.toggle-button {
-fx-graphic: url('icons.jpg');
}
.toggle-button:selected {
-fx-graphic: url('othericon.png');
}

Is it possible to make existing icon lighter on hover

For example I've QToolButton with custom icon
Can I make this icon lighter on hover using QToolButton:hover qss?
Could you please try below options:
option 1:
Try PaletteRole property type
http://doc.qt.io/qt-5/stylesheet-reference.html#paletterole
As you require for hovering,
QToolButton:hover { color: palette(light); }
option 2:
Create a different image with lighter view Icon.
And set the background when you hover on it.
QToolButton:hover { background: url("LighterView.png") ; }

QPushButton focus

I have a pushbutton which its background image gets changed regularly according to the packets ui receives from serial. When the user clicks the button, it becomes red with borders.
pb_Jack1Up ->setStyleSheet("QPushButton {border-image: url(:/ArrowKey/Up_Default.jpg); } QPushButton:focus {border-width: 1px;border-style: solid; border-radius: 4px;}");
Now, what I want is to give the button some effects, to make the user understand that the button is clicked. like make the button go inside when clicked, and when user releases the button border shall no longer be set anymore. However, in my case the button border remains. I cannot also set style sheet with pressed and released slots, because the background image depends on what we receive from serial.
Could anyone help me please?
You can use:
QPushButton { ... }
QPushButton:disabled { ... }
QPushButton:pressed { ... }
QPushButton:focus { ... }
QPushButton:hover { ... }
or take a look at this blog entry.
The button keepsfocus after you release the mouse. Thats why it still has the red border.
You can check that if you activate another widget of the form, clicking, or tabbing, red border dissapears.
Try using
QPushButton:pressed
instead of focus

show border on rollover and select the thumb on click and unselect pre selected thumb

I have some small canvas, and i have to show border around them, i did that using rollover and rollout evenets, (these canvas hold product images), here rollover and rollout are working perfectly fine, but when a user clicks on some canvas, it has to be selected, means it has show the border around it, and rest canvas should work as normal. but when i select another canvas the previously selected canvas should get unselected and new clicked canvas gets the selection,
but the problem which is coming the rollOut event which is applied on canvas, on a click the canvas get selected, but when rollOut takes place it unselect the canvas, i even removed the rollOut listner on the click of a canvas, but in that case, the clicked canvas will not get unselected , when other canvas will be clicked
can.addEventListener(MouseEvent.ROLL_OVER,onRollOverThumb);
can.addEventListener(MouseEvent.ROLL_OUT,onRollOutThumb);
//can.addEventListener(MouseEvent.CLICK,onRollOverThumb);
private function onRollOverThumb(event:MouseEvent):void
{
event.target.setStyle('borderColor','0x000000');
event.target.setStyle('borderThickness','3');
event.target.setStyle('borderStyle','solid');
}
private function onRollOutThumb(event:MouseEvent):void
{
event.target.setStyle('borderColor','0xCCCCCC');
event.target.setStyle('borderThickness','1');
event.target.setStyle('borderStyle','solid');
}
i hope some thing are clear in this, does n e one has worked on this, please reply
Thanks in advance
Ankur sharma
What about implementing a "flag" variable that is set to true when the click occurs. Then, when the ROLL_OUT occurs, check if the flag is true or false. If true, don't do anything, if false, remove/change the border.
private function onRollOverThumb(event:MouseEvent):void
{
if(event.type=='click')
{
for(var j:int=0;j<viewparent.numChildren;j++)
{
viewparent.getChildAt(j).name="false";
}
event.currentTarget.name="true";
for(var i:int=0;i<viewparent.numChildren;i++)
{
if(viewparent.getChildAt(i).name=="true")
{
Canvas(viewparent.getChildAt(i)).setStyle('borderColor','0x000000');
Canvas(viewparent.getChildAt(i)).setStyle('borderThickness','3');
Canvas(viewparent.getChildAt(i)).setStyle('borderStyle','solid');
}
else
{
Canvas(viewparent.getChildAt(i)).setStyle('borderColor','0xCCCCCC');
Canvas(viewparent.getChildAt(i)).setStyle('borderThickness','1');
Canvas(viewparent.getChildAt(i)).setStyle('borderStyle','solid');
}
}
}
else
{
event.currentTarget.setStyle('borderColor','0x000000');
event.currentTarget.setStyle('borderThickness','3');
event.currentTarget.setStyle('borderStyle','solid');
}
}
private function onRollOutThumb(event:MouseEvent):void
{
if(event.currentTarget.name=="false")
{
event.currentTarget.setStyle('borderColor','0xCCCCCC');
event.currentTarget.setStyle('borderThickness','1');
event.currentTarget.setStyle('borderStyle','solid');
}
}
i modified my own code, added one name property to the canvases
can.name="false"
and it's now working,
can n e one tell me, how to put some select and unselect(kind of fade effect) on the border, when the black selection get removed, it shld be removed in some fade manner, can we apply fade effect on border?

Changing the default color on flex validation errors

The examples I've seen seem to show how to change the color that shows when the user actually hovers over the textinput field.
However when the validation fails, a generic textInput border qill have a red line over it. My CSS file uses a border skin for the textInput, so I can't see this line.
I was hoping there was a way to highlight the text box when it failed validation, or re-enable the red line feature. I don't want to get rid of my CSS cos it'll totally blow my color-scheme, but any tweak allowing the error line to show would be much appreciated.
This is the CSS:
TextInput, TextArea
{
border-skin: Embed(source='/../assets/images/input_bg.png', scaleGridLeft=8, scaleGridRight=20, scaleGridTop=8,scaleGridBottom=9);
padding-top:2;
padding-left:2;
font-size:11;
}
anything that extends UIComponent (both TextInput and TextArea do) has a style called errorColor. It defaults to red. You can change this to whatever you want.
Additionally, if you've got an image that you are using as a border, you should probably remove the pixels from the middle so that it is an actual border instead of an overlay.
The only way I've managed to find, is that Validator will change the component's borderColor style. I don't think it can be achieved using an image- you'll have to embed the image in a basic GraphicRectangularBorder subclass or similar. You can then add this to your skin class:
override public function styleChanged(styleProp:String):void
{
super.styleChanged(styleProp);
if (styleProp == "borderColor")
{
if (getStyle("borderColor") == getStyle("errorColor"))
{
// show error outline
}
else
{
// hide error outline
}
}
}

Resources