Posts

Showing posts with the label javafx

setOnAction restrictions and datepicker class

Image
Clash Royale CLAN TAG #URR8PPP setOnAction restrictions and datepicker class I'm writing an application involved in time difference, there is something I don't get it, final DatePicker datePick=new DatePicker(); LocalDate time; Label label=new Label(); datePick.setOnAction(new EventHandler<ActionEvent>(){ public void handle(ActionEvent e){ time=datePick.getValue();//doesn't work, must 'LocalDate time=datePick.getValue(); label.setText(time);//doesn't work must label.setText("Time now:"+time) } }); It gives an error saying "Local variables referenced from an inner class must be final or effectively fine", anyway, all I did, declare 'time' variable inside setOnAction() and it worked, so what was wrong? and 'label.setText(time);' if I don't write some text inside, like 'label.setText("Time now: "+ time);' ,won't work too, that's weird, yet...

Scroll Lock feature using tableView javafx

Image
Clash Royale CLAN TAG #URR8PPP Scroll Lock feature using tableView javafx I want to create a tableView and give scroll lock feature in that view in case of data stream is coming to view. i have created the view and if scroll bar is placed at any location (not at end), the view doesn't get scrolled but if i drag the scroll bar at the end, and continuous data comes, scroll bar remains at end which results in coming data gets displayed. If any one can help to stop getting new data in view even if scroll bar is at end. Thanks By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Open another window on clicking OK button of Alert in JavaFX

Image
Clash Royale CLAN TAG #URR8PPP Open another window on clicking OK button of Alert in JavaFX private void showAlert(Alert.AlertType alertType, Window owner, String title, String message) { Alert alert = new Alert(alertType); alert.setTitle(title); alert.setHeaderText(null); alert.setContentText(message); alert.initOwner(owner); //alert.show(); Optional<ButtonType> result = alert.showAndWait(); if ((result.isPresent()) && (result.get() == ButtonType.OK)) { System.out.println("ALL OK..!"); //Open another window on clicking the OK button } } On this particular section, on clicking OK button, I want to open another window. Usually Button type is used for which an event can be defined by buttonName.setOnAction( event -> { //Action to do } ); Now how do I define this OK as a button Type? ...

How to create a image of a chart with Java

Image
Clash Royale CLAN TAG #URR8PPP How to create a image of a chart with Java I need to create a chart by reading some entries in my DB. I just want to create a image of the chart and create a new png. I prefer to do this with Java native libraries, so far I was able to get the following working. import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.embed.swing.SwingFXUtils; import javafx.scene.Scene; import javafx.scene.image.WritableImage; import javafx.stage.Stage; import javafx.scene.chart.*; import javafx.scene.Group; import java.io.File; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import javax.imageio.ImageIO; public class Test extends Application { @Override public void start(Stage stage) { Scene scene = new Scene(new Group()); stage.setTitle("Imported Fruits"); stage.setWidth(500); stage.setHeight(500); Observ...

How do I add two images, one above the other to a shape in JavaFX?

Image
Clash Royale CLAN TAG #URR8PPP How do I add two images, one above the other to a shape in JavaFX? Please help. I am trying to add two images to the shape: @FXML private Rectangle rectangle; Image img1 = new Image("a.png"); Image img2 = new Image("b.png"); rectangle.setFill(new ImagePattern(img1)); rectangle.setFill(new ImagePattern(img2)); These images have a transparent background. Both should be visible. One above the other. But only one is visible. I will be grateful for the advice. By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Scenebuilder throws nullpointer exception when using customcomponent

Image
Clash Royale CLAN TAG #URR8PPP Scenebuilder throws nullpointer exception when using customcomponent I have a custom component like this: class SelectableVBox extends VBox { Node selectedNode private static PseudoClass selected = PseudoClass.getPseudoClass("selected") SelectableVBox() { super() addEventFilter(MouseEvent.MOUSE_CLICKED, { MouseEvent event -> if (event.button == MouseButton.PRIMARY) { def intersectedNode = NodeUtility.firstParentFullfilling(event.pickResult.intersectedNode, { node -> children.contains(node) }) if (intersectedNode == null) { return } if (selectedNode != null) { selectedNode.pseudoClassStateChanged(selected, false) } selectedNode = intersectedNode selectedNode.pseudoClassStateChanged(selected, true) } }) } } Basically it's a VBox which implements a very light selectionmodel that can then be used t...

Access a JavaFX TextArea within Tab returned from a TabPane

Image
Clash Royale CLAN TAG #URR8PPP Access a JavaFX TextArea within Tab returned from a TabPane I would like to access a text area placed within a Tab. All the Tabs in the TabPane will have a TextArea. Unfortunately Tab is not an interface and there does not seem a way to change the type held inside of the TabPane so I can not see a way to make code know that there is going to be a TextArea inside of the generic tab without keeping a separate list of them somewhere outside. TabPane can only return a Tab and tab does not distinguish that it holds a TextArea and even if I make an extension of Tab and give it to the TabPane it will still only return a Tab. Keeping an outside list seems really hacky and I dont think that would ever be the intended design. So what am I missing here. I am not using FXML. You can of course cast the content of a Tab . A more direct way than looking for it in this node is probably more hacky than storing the TextArea s in a proper data s...