Hiding text in a button - javafx

I have a certain set of buttons registered so that they can be executed using letters in a keyboard or by mouse click. But I want to hide the text in the button from the user so that it looks more natural.
Heres part of the code:
ToggleButton btn1 = new ToggleButton("");
btn1.setMnemonicParsing(true); // instruction to parse mnemonic
btn1.setText("_7");
Now instead of the button showing a 7 in the middle I want it to be hidden but still function the same. I have a feeling it has something to do with the setVisible() method but I'm not sure how to use it for just the text inside the button instead of the entire button itself.

Most probably you can't do both at the same time. If you want to trigger the button using MneomonicParsing, then you have set the text and it will be visible in the button.
Why don't you use a onKeyPressed method of the container of those buttons instead? Then you don't have to set any text on the button. Like this:
container.setOnKeyPressed(k->{
switch(k.getCode()){
case NUMPAD7:
case DIGIT7: btn1.fire();
break;
//implement other cases
}
});

Related

Is there a way to show tooltip on disabled QWidget

I have a Qt form, where I have a button and menu. For various reasons I can disable certain elements, e.g button or some actions in the menu.
Is there a way I could show a tooltip or when the mouse is hovered over the disabled button or menu item with an explanation as to why it is disabled?
I am using Qt 4.8.
Thanks!
You can set the tooltip dynamically based on the state of the QWidget or by simply toggling both at the same time. Upon disabling/enabling the widget from somewhere just call QWidget::setToolTip(...) with the QString you want the tooltip to display when hovering with the mouse over the given widget. For example if you have a public slot called toggleButton(bool toggleFlag) which toggles the enable-setting of a button you can do:
void MyWidget::toggleButton(bool toggleFlag) {
this->ui->myButton->setEnabled(toggleFlag);
this->ui->myButton->setToolTip(toggleFlag ? QString("Enabled wohoo!") : QString("Disabled because I like it"));
}
You can of course do also change the tooltip by calling QWidget::isEnabled() and act upon its return value. Since you haven't given any code I can only assume how you toggle your button(s) so that's all I can give you for now.
UPDATE: It was pointed in the comments that tooltips don't work with disabled widgets due not receiving mouse events. Both statements are not true (note that I have used the same tooltip message since due to lack of minimal working example I didn't want to write a whole new project from scratch and used an existing one of mine instead):
Hovering a disabled button triggers the tooltip
Hovering an enabled button triggers the tooltip

wxPython issue in changing button text

I am working on a wxPython app where I have a button with label text 'Allocate'. Additionally I also have 2 radio options on my app namely 'UnAllocated' and 'Allocated'. When the app launches by default the radio option 'UnAllocated' is selected and the button has label text as 'Allocate'. I have made event driven code to change the label text of the button from 'Allocate' to 'Re-Allocate' upon selecting the radio option 'Allocated'. Uptill now everything is fine and code works as intended.
Now the problem is in the event of radio option 'Allocated' the button label does gets a new label text as 'Re-Allocate' however it is overwriting the previous label text instead of changing. Then as soon as I bring my mouse cursor on the button the text gets refreshed and appears clean and clear. Below is my Code
def rdoAllocated_Click(self, event):
self.btn_Allocate.SetLabelText('Re-Allocate')
def rdoUnAllocated_Click(self, event):
self.btn_Allocate.SetLabelText('Allocate')
is there a way of refreshing the button label text automatically after the change to display clearly the new text instead of unreadable overwritten text.
Here is the image how it looks when getting updated
Try calling self.btn_Allocate.Refresh() This can happen sometimes, depending on platform and widget types. The Refresh simply tells the system to send a paint event in the near future, and will most-likely take care of the problem for you. If not then you may need to call the parent window's Refresh instead.

Genexus - Disable Text Block used as button

I have a Text Block that I use as a button (with enter event) and when I press it it takes a while to do what it has to do, so you can click more than once the button and it does it twice or more times. So what I want to do is to disable or to hide the text block while its doing its job, but the text block only hides when it exits the enter event, which is to late because I already could pressed several times the buttom.
How can I find a solution for this? Is there a way to disable or hide the text block when I enter the enter event but before it exit the event?
I suppose you are calling a procedure. Try to use
MyProcedure.Submit()
instead of
MyProcedure.Call()

How to make ButtonGroup visible dynamically from another command button?

I have action pane's MyButtonGroup's visible property set to 'no'.
What I want to do is to show (to set its visible property to 'yes') MyButtonGroup when I click Line view button.
I overrode Line view's method gotFocus:
MyButtonGroup.visible(true);
super();
but I also want MyButtonGroup visible property to be false if Line view button is not focused / clicked
for this I overrode the lostFocus method on Line view
MyButtonGroup.visible(false);
super();
so the lostFocus method "does not work", I mean when Line view button is not focused anymore
MyButtonGroup remains visible.
how can I solve it?
Never use gotFocus or lostFocus.
Use the clicked method of LineViewButton and HeaderViewButton instead.
See my pastebin for an example.
That said, you are on the wrong track, the button group would be better placed on the action pane directly above the lines.

Custom TextInput component loses focus but still contains cursor?

I have a custom TextInput that listens for the FocusEvent.FOCUS_IN and FocusEvent.FOCUS_OUT events:
textDisplay.addEventListener(FocusEvent.FOCUS_IN, onFocusInHandler);
textDisplay.addEventListener(FocusEvent.FOCUS_OUT, onFocusOutHandler);
My onFocusInHandler function basically removes a "promptview" that tells the user to type in a value, with the onFocusOutHandler doing the opposite.
For example, if the TextInput text was backspaced to a blank value and the user clicks out of the TextInput box, it would show a "Please enter a value" light-gray prompt in the TextInput.
This works fine until the user clicks our custom "Clear" button. The clear button sets the text to "", and I can tell the FocusEvent.FOCUS_OUT is received because the prompt text is set to visible (its not being set anywhere else). The problem is, the cursor remains in the box as if it still has focus, so if the user immediately starts typing, both the prompt text "Please enter a value" and the user-entered text appears over the gray text, which looks pretty ugly and unreadable.
Why does the TextInput receive the FocusEvent.FOCUS_OUT event if it's not actually losing focus? Is there any way I can get around this?
Option 1. Use the Spak TextInput in Flex 4.1 or 4.5. This already provides a promptDisplay by default (as mentioned in the comments)
Option 2. Take a look at the focus-skin. This skin class is usually placed on top of the normal skin. There could exist some focus ambiguity between these two. Try using a custom focus-skin without a textDisplay and clear button.
Option 3. Not only use a focus event to show or hide the prompt, but also look at the content of the TextInput. You don't want to display a prompt when the text is set by binding as wel.

Resources