Hover effect over icon - javafx-2

I would like to create buttons like these for settings panel navigation:
Can you tell me how I can create this hover effect over the icons? The most difficult part for me is to create CSS code which looks like the the picture.

Although the above answer works. You should really do this completely in CSS using pseudo-selectors:
java:
btnsa.getStyleClass().add("myButton");
css:
.myButton {
-fx-background-color:transparent;
}
.myButton:hover {
-fx-background-color:#dae7f3;
}

You have to use MouseEntered and MouseExited events for getting hover effects over the icons.
try this its working.........
btnsa.setStyle("-fx-background-color:transparent;");
btnsa.setGraphic(new ImageView(new Image(getClass().getResourceAsStream("JavafxSm.gif"))));
btnsa.setOnMouseEntered(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent t) {
btnsa.setStyle("-fx-background-color:#dae7f3;");
}
});
btnsa.setOnMouseExited(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent t) {
btnsa.setStyle("-fx-background-color:transparent;");
}
});
some snap shots of above code......

Instead, you can do just 1 line code in CSS, if your FXML file connected with CSS
yourButtonId:hover{-fx-background-color: #6695e2}

Related

How to make JavaFX ColorPicker disabled without dim appearence?

I've been trying to disable a javafx.scene.control.ColorPicker without dimming it in my UI. Meaning that I want it to look as enabled (enabled appearence), but just do not respond to any command, also not showing the table of colors on mouse click (actually disabled). This behaviour will be interchangeable with normal behaviour, according to the system state (i.e., sometimes color picker will behave as normal).
I've tried some options, but none seemed to work, as follows:
1. Use setEditable(boolean):
myColorPicker.setEditable(false);
This just doesn't work, the color picker remains editable.
2. Use setDisable(boolean) and setOpacity(double) together:
myColorPicker.setDisable(true);
myColorPicker.setOpacity(1.0f);
This makes the color picker actually not editable, and the resulting color picker appear a little less dimmed than just using setDisable(true), but still not the appearence of an enabled color picker.
3. Overriding onMouseClick(), onMousePressed() and onMouseReleased() with empty implementations:
myColorPicker.setOnMouseClicked(new EventHandler <MouseEvent>() {
public void handle(MouseEvent event) {
System.out.println("Mouse clicked.");
}
});
myColorPicker.setOnMousePressed(new EventHandler <MouseEvent>() {
public void handle(MouseEvent event) {
System.out.println("Mouse pressed.");
}
});
myColorPicker.setOnMouseReleased(new EventHandler <MouseEvent>() {
public void handle(MouseEvent event) {
System.out.println("Mouse released.");
}
});
The above approach printed on my console the corresponding messages, but color picker still responded to mouse click (showing the color table and allowing to pick a new color). Also tried to override setOnAction(EventHandler<ActionEvent>), but with same effect (except that no console printing when I clicked the color picker).
Here it is the excerpt of my FXML:
<VBox fx:controller="mypackage.ElementConfigWidget"
xmlns:fx="http://javafx.com/fxml" fx:id="root" styleClass="elementConfigPane">
<HBox id="elementInfo">
(...)
<ColorPicker fx:id="elementColor" styleClass="elementColor" />
</HBox>
(...)
</VBox>
Here it is my CSS exerpt:
.elementColor {
-fx-cursor: hand;
-fx-background-color: #fff;
-fx-focus-color: transparent;
-fx-faint-focus-color: transparent;
-fx-pref-width: 50.0;
}
I actually expected setEditable(boolean) to solve my problem, by keeping the element appearence and ignoring input actions. What am I missing?
Thanks a lot!
I manage to achieve it with some CSS
.Also you need to setDisable(true) and opacity to 1.0
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ColorPicker;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) throws Exception {
ColorPicker myColorPicker = new ColorPicker();
myColorPicker.setDisable(true);
myColorPicker.setOpacity(1.0);
Scene s = new Scene(myColorPicker);
s.getStylesheets().add(this.getClass().getResource("test.css").toExternalForm());
primaryStage.setScene(s);
primaryStage.show();
}
}
And the test.css
.color-picker > .label:disabled {
-fx-opacity : 1.0;
}

org.eclipse.swt.browser.Browser does not open in Eclipse RAP application

Wonder if somebody can help me with this. I am trying to open an embedded browser in an Eclipse RAP applications. All examples I have seen look something like:
link.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent event) {
try {
Browser b = new Browser(parent, SWT.NONE);
b.setText("<html><body>This is Unicode HTML content from memory</body></html>");
} catch (SWTError e) {
// Error handling here
}
}
});
That doesn't do anything (visually) though. When I replace the Browser with ExternalBrowser like so:
link.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent event) {
try {
int browserStyle = ExternalBrowser.LOCATION_BAR;
ExternalBrowser.open( "myPage", "http://www.stackoverflow.com", browserStyle );
} catch (SWTError e) {
// Error handling here
}
}
});
It works. Although not exactly as desired.
I am using Eclipse RCP 1.4.2 on OS X 10.8.2.
Any insight is highly appreciated.
When you create a new widget, you have to trigger a re-layout to make it visible. Depending on your layout, it may be sufficient to call parent.layout(). If the parent is also contained in a layout and shrunken to its preferred size, you will have to call layout() on its parent. If unsure, layout the top-level shell.

Is it possible to forbid selection in TextField?

I have a small problem: my text field keeps selecting itself, for example if I alt-tab from and to application.
For my application, text selection is not needed and will not be used - so I want to disallow this annoying behavior. Actually, just setting selection color to transparent or white will work fine.
Is there some way to do this?
The following css fixed the problem for me:
-fx-highlight-fill: null;
-fx-highlight-text-fill: null;
You can disable text selection for key events:
myTextField.addEventFilter(KeyEvent.KEY_TYPED, new EventHandler<KeyEvent>() {
#Override
public void handle(KeyEvent inputevent) {
if (!myTextField.getSelectedText().isEmpty()) {
myTextField.deselect();
}
}
});
For mouse events you could also use:
myTextField.addEventFilter(MouseEvent.MOUSE_DRAGGED, new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent event) {
if (!myTextField.getSelectedText().isEmpty()) {
myTextField.deselect();
}
}
});
Super late for an answer, but I have a better solution.
Instead of disabling the style for selected text or managing mouse events, it's better to directly manage the selectedTextProperty().
The advantages of this solution are:
The selection properties will always be empty selection
Double clicks are also covered, not only mouse drag events
The code...
textField.selectedTextProperty().addListener((observable, oldValue, newValue) -> {
if (!newValue.isEmpty()) textField.deselect();
});

GXT ContentPanel's header align to the right

I'm using gxt to my application.
I won't to align the ContentPanel's header ToolButtons to the left instaed to the right (which is the defualt)
there is no method such as setHorizontalAlogment.
any suggestions how to do that?
I don't see any method offered by GXT to achieve this. But I found a way to do this. Here is the code that demonstrates how you can achieve this.
public class CustomPanel extends ContentPanel {
public CustomPanel() {
super();
addListener(Events.Render, new Listener<BaseEvent>() {
#Override
public void handleEvent(final BaseEvent be) {
final HorizontalPanel panel = getWidgetPanel(getHeader());
panel.setStyleAttribute("float", "left");
}
});
}
//widgetPanel is private. It can be accessed using JSNI
private native HorizontalPanel getWidgetPanel(Component header)/*-{
return header.#com.extjs.gxt.ui.client.widget.Header::widgetPanel;
}-*/;
}
try to set the position through the style .. float: left

Display a new view from within a custom control

I have a custom button which inherits from UIButton. I'm handling the TouchUpInside event and want to display a view on top of the current View. Is there such a thing as Dialogs like in Windows development? Or should I do this in another way?
[MonoTouch.Foundation.Register("HRPicker")]
public class HRPicker : UIButton
{
public HRPicker () : base()
{
SetUp();
}
public HRPicker(NSCoder coder) : base(coder)
{
SetUp();
}
public HRPicker(NSObjectFlag t) : base(t)
{
SetUp();
}
public HRPicker(IntPtr handle) : base(handle)
{
SetUp();
}
public HRPicker(RectangleF frame) : base(frame)
{
SetUp();
}
public void SetUp()
{
TouchUpInside += HandleTouchUpInside;
}
void HandleTouchUpInside (object sender, EventArgs e)
{
//I want to display a View here on top of the current one.
}
}
Thanks,
Yes, you have a couple options:
ModalViewController - is called from any UIViewController and overlays a ViewController in the foreground.
UIPopoverController - is a native control that takes a UIViewController and has hooks for presentation and dismissal
WEPopoverController - is a re-implementation of UIPopoverController and allows you to customize the layout, size, and color of the Popover container.
ModalViewController: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html
UIPopoverController: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIPopoverController_class/Reference/Reference.html
WEPopoverController: https://github.com/mono/monotouch-bindings/tree/master/WEPopover
Update: Regardless of which option you use you must call the presentation of the Popover / Modal view from the main thread:
using(var pool = new NSAutoReleasePool()) {
pool.BeginInvokeOnMainThread(()=>{
// Run your awesome code on the
// main thread here, dawg.
});
}
The equivalent of dialog in Cocoa is UIAlertView: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIAlertView_Class/UIAlertView/UIAlertView.html
Check out this question for an example of how to use it: Showing an alert with Cocoa
The code should be pretty easy to translate to c# and MonoTouch. But here is a simple example: http://monotouchexamples.com/#19

Resources