I have an ImageView in a Pane, and the pane has been set a MouseEventHandler to do some actions.
The ImageView's Image is defined in a CSS file as below:
.imageView{
-fx-image: url("image/normal.png");
}
.imageView:pressed{
-fx-image: url("/image/press.png");
}
Under normal status, the ImageView's image is 'normal.png'. When the user presses the ImageView, its image will be changed to 'press.png'. Then, when released, its image will be changed back to 'normal.png'.
However, if the user does not press on the ImageView's image exactly, even though Pane's MouseEvent is trigged, the image will not be changed.
How can I do to change ImageView's image when its parent Pane is pressed. For instance, on Android, the image will be switched automatically. It is very convenient.
Add a style class to the pane ("image-container", for example), then in the css do
.imageView{
-fx-image: url("image/normal.png");
}
.image-container:pressed .imageView {
-fx-image: url("/image/press.png");
}
Related
How to add button with layout "icon only" to pdf using PDFBOX?
create a button with this properties
I have try this example before, but just can't set to the button properties I want.
[edit]
This the button I created using acrobat.
And This the button i created using PDFBOX
My question is in PDFBOX how to create a button similar to the button created in acrobat?
The desired layout information may be stored in the TP entry of the appearance characteristics dictionary:
Key
Type
Value
TP
integer
(Optional; pushbutton fields only) A code indicating where to position the text of the widget annotation’s caption relative to its icon:0 No icon; caption only1 No caption; icon only2 Caption below the icon3 Caption above the icon4 Caption to the right of the icon5 Caption to the left of the icon6 Caption overlaid directly on the iconDefault value: 0.
(ISO 32000-1, Table 189 – Entries in an appearance characteristics dictionary)
Thus, you may want to try setting the TP entry of the PDAppearanceCharacteristicsDictionary fieldAppearance in the referenced code to 1.
I am trying to make the AnchorPane resize with its parent JFXDialoglayout. I tried this in scene builder, but wouldn't let me position/resize it correctly. Now I am trying to do it manually instead as seen below. As seen in the code I tried to bind the width and height of the AnchorPane to the JFXDialoglayout, but this did still not work. I also tried setting the pref height/width of them both equally, still did not work. The problem is that the height of the AnchorPane is smaller than the JFXDialogLayout but the width is the same. How do I make the heights equal?
private JFXDialogLayout getDialogLayout() {
JFXDialogLayout layout = new JFXDialogLayout();
layout.setPrefWidth(600);
layout.setPrefHeight(300);
AnchorPane pane = new AnchorPane();
pane.prefHeightProperty().bind(layout.prefHeightProperty());
pane.prefWidthProperty().bind(layout.prefWidthProperty());
Label heading = new Label("Heading");
Text body = new Text("This is the body of the dialog.");
JFXButton button = new JFXButton("ACCEPT");
pane.getChildren().addAll(heading, body, button);
layout.getChildren().addAll(pane);
return layout;
}
I have been making JavaFX apps using SceneBuilder and Netbeans for quite some time. What you are trying to do, can be done easily at the Tab "Layout" and more specific in the tab "Anchor Pane Constraints". Inside the four boxes you have to put the standard distance you like, between the Hbox sides and the Anchor Pane outer sides. Please, check the screenshot below, with my example for a Horizontal Box inside an Anchor Pane. The HBox gets smaller or bigger when the user resizes the Anchor Pane.
Problem : It is not possible to simply 'add' ContextMenu to a Canvas or Pane element via addContextMenu(menu), which works only with javafx.scene.control elements (and neither Canvas or Panel extends this class).
Question : Is there any 'clean' way to 'register' ContextMenu item to a Canvas element? I expect standard behavior of this menu (to show after RMB clicked on Canvas element, autohide when clicked with LMB etc.).
Canvas canvas = ... ;
ContextMenu menu = ... ;
canvas.setOnContextMenuRequested(e -> menu.show(canvas, e.getScreenX(), e.getScreenY()));
James_D's solution may not dismiss the menu when clicking the canvas while the context menu is visible. See this bug :
https://bugs.openjdk.java.net/browse/JDK-8095591
So instead, I suggest using :
Canvas canvas = ... ;
ContextMenu menu = ... ;
canvas.setOnContextMenuRequested(e -> menu.show(canvas.getScene().getWindow(), e.getScreenX(), e.getScreenY()));
Maybe you can use Chrome extension's contextMenu. here is the official document.
The only issue so far I find is that the Context type for a canvas is not clear. ["all"] works but is not a good way.
I want to change this filter icon to another one, I have tried this method setFilterButtonProperties(newButton);
but it doesn't work.
here the image which I want to change.
Try this one
Button newButton=new Button("");
newButton.setSize("18px", "18px");
newButton.setIcon("[SKIN]/RecordEditor/add.png");
listGrid.setFilterButtonProperties(newButton);
Note: Change the icon path and size as per your requirement.
How could I change the Tabs close icon X to an image in javafx? I have tried setGraphic(), but it only takes a node... the image i want to set it to is http://eclipse-icons.i24.cc/ovr16/progress_rem.gif
Make the image a valid node using ImageView, but that seems to be for icons.
Tab tab = new Tab();
Image image = new Image("http://eclipse-icons.i24.cc/ovr16/progress_rem.gif");
ImageView iv = new ImageView(image);
tab.setGraphic(iv);
Get rid of the default shape in CSS or write your own or use a background image
.tab-close-button {
-fx-background-color: transparent;//-fx-mark-color;
-fx-shape:null;
-fx-background-image: url("/progress_rem.gif");
}
You'll have to provide your own click handler without the css shape, or something to click on.
This is what you get with css.