Disable clickable slider from Sencha GXT - java

I am trying to add a slider as per (http://www.sencha.com/examples/#ExamplePlace:slider).
At the moment i use GWT 2.6 and Sencha GXT 3.1 Beta
The slider works, but i am able to change the value by just clicking somewhere on the slider. This in turn can mess up the value when i go to retrieve it.
TextField firstName = new TextField();
final Slider slider = new Slider();
slider.setMinValue(0);
slider.setMaxValue(10);
slider.setIncrement(1);
slider.setValue(5);
slider.addValueChangeHandler(new ValueChangeHandler<Integer>() {
#Override
public void onValueChange(ValueChangeEvent<Integer> event) {
firstName.setText(slider.getValue().toString());
}
});
I want to be able to update the field when the value is changed on the Slider. But the slider value should not be changed without dragging the "arrow". If you click somewhere on the slider should/could update the arrowhead to the chosen position though.
Anyone knows if its possible to disable clickable on the slider or do this in a better way? Or at least update the slider "arrow" to where someone clicked?

It is working in my scenario.
public void onValueChange(ValueChangeEvent<Integer> event)
sliderDetail.setValue(event.getValue());
sliderDetail.redraw();
firstName.setText(slider.getValue().toString());

Related

Edit "app" attribute of xml element

So I got following problem:
I'm currently developing a sensor app and I'd like to check if the sensors are available or not. If they aren't, I want to change the color of a button (which starts an activity where the value of the sensor is being displayed) to grey.
Sadly, I can't just change the background color of the button because I'm using the Circle Button Library by Markushi.
This button looks like this:
<at.markushi.ui.CircleButton
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/gyroscope"
app:cb_color="#color/colorMain"
app:cb_pressedRingWidth="8dip"
android:id="#+id/gyroscope"
android:layout_alignLeft="#+id/temperature"
android:layout_alignStart="#+id/temperature"
android:layout_below="#+id/title"/>
As you can see this attribute defines the color.
app:cb_color="#color/colorMain"
My Question is: How can I change this color programmaticly in this method?
public void testSensors() {
if (testManager.getDefaultSensor(Sensor.TYPE_TEMPERATURE) == null) {
}
}
EDIT:
setColor doesn't really work. There is this border left. (see image)
Also: I'm using #616161 as the new color.
EDIT2:
Found out, that the border is caused by the transparent circle thing which gets bigger, when the button is pressed. So basically removing this circle thing will be fine. I try to find an answer on my own :)
CircleButton button;
button = (Button)findViewById(R.id.buttonId);
public void testSensors() {
if (testManager.getDefaultSensor(Sensor.TYPE_TEMPERATURE) == null) {
button.setColor(Color.parse("#000000"));
}
}
If you are using normal button then
button.setBackgroundColor(ContextCompat.getColor(context,R.color.colorAccent));
You can use
1) Color.parse("#000000")
2) ContextCompat.getColor(context,R.color.yourColor)
You can use the setColor() method of the circleButton, as you can see from the source code here .
So basically what you need to do is get a reference to your circle Button, using the findViewById method of your activity. then
public void testSensors() {
if (testManager.getDefaultSensor(Sensor.TYPE_TEMPERATURE) == null) {
myCircleButton.setColor(Color.parse("#000000"));
}
}
Also if you are seeing the pressed ring, then that means the state of the button is somehow in the pressed state, so try setting it o false using the setPressed(false) method.
To answer this problem (if anyone has the same):
You can set the animation to 100. This somehow disables the circle.
For some reason the color of the button has now a fixed color (dark grey) but scince this is fine to me and I don't want to cry under my table, I just let it be and move on with my project.
mCircleButton.setAnimationProgress(100);
Thank you all so much for your help! :)

how to get rid of visual effect when disabling buttons in java

When I'm setting the button to be disabled using this:
jButton.setEnabled(false);
then there is this visual effect visible on the second element ->
How can I disable the button, but keep the the look of the first element?
how to get rid of visual effect when disabling buttons
Companies spend millions of dollars to develop a UI can is common and can be used by all users.
How is the user suppose to know that the button is disabled if there is no visual indication?
Anyway, (rant finished) you can manually set the disabled icon:
button.setDisabledIcon( button.getIcon());
If you also happen to have text on the button the text will still be disabled so instead of a disabled icon you can use a custom ButtonModel:
button.setModel( new DefaultButtonModel()
{
#Override
public boolean isArmed()
{
return false;
}
#Override
public boolean isPressed()
{
return false;
}
});

How do I change the focus on buttons of JFace WizardPage?

I have implemented a JFace Wizard with 2 WizardPages.
By default, the first WizardPage has these 4 Buttons:
Back (disabled)
Next (focused)
Cancel
Finish (disabled)
Now I want to set the default focus on the Cancel Button. How do I do that?
Removing the focus and setting it to some Control of the page's content would also be ok.
I tried setting the focus to a Button in the content layout of the WizardPage, but this only sets me a second focus on the immediateButton. The focus on the Next button is still there, and the Next button reacts to pressing enter, which is what I want to avoid.
#Override
public void setVisible(boolean visible) {
super.setVisible(visible);
if (visible) {
immediateButton.setFocus();
}
}
How can I access the Dialog buttons and change their focus?
The Next button does not actually have focus, rather it is the Shell Default button.
The logic in WizardDialog makes either Next or Finish the default button and there does not seem to be a way to change this.
You may be able to override this by calling getShell().setDefaultButton(button) in your wizard page.
Update: Testing this you can do it in setVisible but you need to use Display.asyncExec to make the code run at the right time:
final Shell shell = getShell();
shell.getDisplay().asyncExec(() -> shell.setDefaultButton(immediateButton));
above is for Java 8, for Java 7 or earlier:
shell.getDisplay().asyncExec(new Runnable()
{
#Override
public void run()
{
shell.setDefaultButton(immediateButton);
}
});

Show Tooltip on disabled Control in JavaFX

It is possible to show a Tooltip on a disabled Control?
I have the following code and this doesn't work:
txt_searchText.setDisable(true);
txt.searchText.setTooltip(new Tooltip("Message"));
Has anyone a solution for that problem?
Thx
The answer is no. Currently you cannot show a tooltip on disabled Node, for the simple reason that disabled Nodes do not receive any MouseEvents.
You can see the issue being raised in the official issue tracler here (require login) : https://javafx-jira.kenai.com/browse/RT-28850
One solution to your problem could be to wrap your Control into something else.
For example, put your control into another Control, like a SplitPane or a Label. Then you could apply your tooltip to that wrapper and disable your first control.
Not directly but you can warp your button into another control and while your button could be disable or not, the control will answer to mouse movements.
Button button = new Button("Click me"); //create a button
button.setDisable(true); //disable button in some way
SplitPane splitPane = new SplitPane(button); //warp it into a splitPane
splitPane.setTooltip(new Tooltip("I'm the Tooltip Massage")); //Crete a tooltip
Node that SplitPane extends "Controls" not Region and not pane.
so it's a Control and best for our case (warping buttons).
you must always use a Control to warp another control. other way you will not have access to setTooltip() method.
Here's a workaround using the CustomMenuItem class:
customMenuItem.getContent().setOnMouseEntered(e -> {
if (customMenuItem.isDisable()) {
Tooltip.install(customMenuItem.getContent(), tooltip);
} else {
Tooltip.uninstall(customMenuItem.getContent(), tooltip);
}
});
Another solution is to filter mouse events on the parent and display a tooltip on the disabled items. A typical example is a toolbar:
toolBar.addEventFilter(MouseEvent.MOUSE_MOVED, e -> {
var node = toolBar.getItems().stream()
.filter(Node::isDisabled)
.filter(n -> n.contains(n.parentToLocal(e.getX(), e.getY()))).findFirst();
if (node.isPresent() && node.get() instanceof Control control) {
toolBar.setTooltip(control.getTooltip());
} else {
toolBar.setTooltip(null);
}
});

Java - Icon/image is grey on a disabled JButton

I'm making minesweeper for a school project. When the player wins or loses, the mines are revealed. Their buttons are disabled, and icons of flags/mines will appear. The problem is that the icons turn grey when the buttons are disabled. Is there a way around this?
I have also tried setting the text of the JButton to something like "<html><img src=\"res\\mine.png\"/></html>" but it showed some weird image.
Update:
I tried using setDisabledIcon() but nothing's showing up. Here's some pseudo-code
The buttons I use for the minefield is a class called Field, which extends JButton
mouseReleased(mouseEvent e) {
Field fieldClicked = (Field)e.getSource();
if fieldClicked is mine {
fieldClicked.setEnabled(false);
gameTimer.stop();
setLost(true);
loop through 2D array of fields {
if field is a mine {
field.setDisabledIcon(Field.mineIcon);// public static final icon of Field. mineIcon = new ImageIcon("res\\mine.png")
field.setEnabled(false);
}
}
}
}
Figured this out in a test
For some reason
clickedButton.setDisabledIcon(mineIcon)
Alone doesn't do anything.
But:
clickedButton.setIcon(mineIcon)
clickedButton.setDisabledIcon(mineIcon)
Will show whatever icon I wanted
a JButton actually allows seven associated images: the main image (use
setIcon to specify it if not supplied in the constructor), the image
to use when the button is pressed (setPressedIcon), the image to use
when the mouse is over it (setRolloverIcon, but you need to call
setRolloverEnabled(true) first), the image to use when the button is
selected and enabled (setSelectedIcon), the image to use when the
button is disabled (setDisabledIcon), the image to use when it is
selected but disabled (setDisabledSelectedIcon), and the image to use
when the mouse is over it while it is selected
(setRolloverSelectedIcon).
- http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JButton.html
so use setDisabledIcon(ImageIcon)
The greyed image is the automatically generated one, in case you want a different icon, use setDisabledIcon()
Icon disabledIcon = new ImageIcon("youricon.gif");
button.setDisabledIcon(disabledIcon);

Categories

Resources