javafx

ListView with custom content in JavaFX

匆匆过客 提交于 2020-01-12 05:44:06
问题 How i can make custom ListView with JavaFx for my app. I need HBox with image and 2 Labels for each line listView. 回答1: You need to provide a custom CellFactory via ListView.setCellFactory(...) Working example public class CustomListView extends Application { private static class CustomThing { private String name; private int price; public String getName() { return name; } public int getPrice() { return price; } public CustomThing(String name, int price) { super(); this.name = name; this

How to initialize JavaFX controllers with the same model object?

三世轮回 提交于 2020-01-11 15:48:10
问题 Scenario I am creating a GUI where multiple views reference the same model object. What I am Accustom to In Swing, if i want all the views to reference the same model i would pass the model into the constructor. What I am Currently Doing In JavaFX, I am passing the model around by having a setter method in the views/controllers (menubars, split panes, tabs, ...), after each view/controller has been loaded. I find this very tacky and cumbersome. Additionally, I find it won't work because in

Can't set the value of a static TextField in javafx [duplicate]

喜你入骨 提交于 2020-01-11 14:10:16
问题 This question already has an answer here : javafx 8 compatibility issues - FXML static fields (1 answer) Closed 2 years ago . I'm working on a program for Insurance purposes and there I've a textfield called Reference Key this reference key is generated randomly every time I View the panel the other Scenes and classes needs this Reference Key , so I've made it static so that all the classes can reach this Instance directly ! My problem is that when I set the text for the textfield I get an

Dynamically change the color of a Rectangle in Javafx

南笙酒味 提交于 2020-01-11 13:59:17
问题 I am creating a two javafx.scene.shape.Rectangle objects in a GridPane and doing the following. rectArray = new Rectangle[2]; boardGrid.setStyle("-fx-background-color: #C0C0C0;"); rectArray[0] = new Rectangle(12,12); rectArray[0].setFill(Color.AQUA); boardGrid.add(rectArray[0], 2, 0); rectArray[1] = new Rectangle(12,12); rectArray[1].setFill(Color.BLACK); boardGrid.add(rectArray[1], 2, 1); Button buttonStart = new Button("Change color"); buttonStart.addEventHandler(MouseEvent.MOUSE_CLICKED,

Adding Node's animated to a VBox

我与影子孤独终老i 提交于 2020-01-11 13:57:07
问题 I am looking for a solution to add node's with fade-in or flipping or any animation. Thanks for any help. I found the same question but without any further help here: Animated component adding-delete in a VBox 回答1: As jewelsea already mentioned, you would use Transitions. Here is an example of how to do it for your use case : public static void addFadingIn(final Node node, final Group parent) { final FadeTransition transition = new FadeTransition(Duration.millis(250), node); transition

ListView CellFactory - How to remove cells correctly?

萝らか妹 提交于 2020-01-11 13:19:31
问题 I have a ListView that I am working to add a ContextMenu to. I have the ContextMenu working find but have another issue. My setCellFactory code, used to setup the context menus: lvAppetites.setCellFactory(lv -> { ListCell<Appetite> cell = new ListCell<>(); ContextMenu contextMenu = new ContextMenu(); MenuItem editAppetiteMenu = new MenuItem(); editAppetiteMenu.textProperty().bind(Bindings.format("Edit ...")); editAppetiteMenu.setOnAction(event -> { // Code to load the editor window

javafx mediaview only the audio is playing

瘦欲@ 提交于 2020-01-11 13:17:27
问题 Im trying to embed a video in a website to a mediaview of a simple javafx application. Ive got a sample code which I used as my javafx code. It opens the scene and plays the audio but wont play the video. How can I make it play the audio? Im using netbeans IDE 8.0.2,JavaFx 8 and scene builder 2.0 The Code ive tried is below. Thanx in advanced. @FXML MediaView mdv; Media media; public static MediaPlayer mpl; @Override public void initialize(URL url, ResourceBundle rb) { media=new Media("http:/

how to draw a straight line in javafx that updates itself when the user moves the mouse?

丶灬走出姿态 提交于 2020-01-11 13:05:49
问题 So, I know how to do free hand lines but I want a straight line so when a user clicks a point to the point where the user releases the mouse and when the user drags the mouse the end point should move with the mouse i.e similar to drawing straight lines in the paint app. Presently working with this code: public class JavaFX_DrawOnCanvas extends Application { @Override public void start(Stage primaryStage) { Canvas canvas = new Canvas(400, 400); final GraphicsContext graphicsContext = canvas

how to draw a straight line in javafx that updates itself when the user moves the mouse?

邮差的信 提交于 2020-01-11 13:05:38
问题 So, I know how to do free hand lines but I want a straight line so when a user clicks a point to the point where the user releases the mouse and when the user drags the mouse the end point should move with the mouse i.e similar to drawing straight lines in the paint app. Presently working with this code: public class JavaFX_DrawOnCanvas extends Application { @Override public void start(Stage primaryStage) { Canvas canvas = new Canvas(400, 400); final GraphicsContext graphicsContext = canvas

How to trigger an event on focus out for a textfield in javafx using fxml?

风流意气都作罢 提交于 2020-01-11 11:56:11
问题 I have this function in the controller class of the relevant fxml. I need this function to be fired on focus out from a textfield, but scene builder doesn't have an event similar to onfocusout. How to achieve this using the control class? @FXML private void ValidateBikeNo(){ Tooltip error = new Tooltip("This bike no exists"); BikeNoIn.setTooltip(error); } 回答1: You can attach a focusListener to the TextField and then execute the code inside it. The listener can be attached inside the