logo
down
shadow

Add constraints to lines in javaFX


Add constraints to lines in javaFX

By : Mohammad Mehrabi
Date : October 22 2020, 08:10 PM
this will help Here is an example. This example does not use Circle.setTranslate#. It uses Circle.setCenter#. It also uses Math.hypot to keep track of the Line length. If the line length becomes greater than or equal to 100, the change in the shape movements is subtracted.
code :
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.stage.Stage;

public class TableViewDemo2 extends Application
{

    double sceneX, sceneY;

    Circle circle = new Circle(15, Color.RED);
    Circle circle2 = new Circle(15, Color.BLUE);
    Line line = new Line();

    private Line connectLines(Line line, Circle startNode, Circle endNode)
    {
        line.startXProperty().bind(startNode.centerXProperty());
        line.startYProperty().bind(startNode.centerYProperty());
        line.endXProperty().bind(endNode.centerXProperty());
        line.endYProperty().bind(endNode.centerYProperty());

        return line;
    }
    //mouse pressed event
    EventHandler<MouseEvent> mousePressed = new EventHandler<MouseEvent>()
    {
        @Override
        public void handle(MouseEvent e)
        {
            System.out.println("pressed");

            sceneX = e.getSceneX();
            sceneY = e.getSceneY();

            Circle tempCircle = ((Circle) e.getSource());
            tempCircle.toFront();
        }
    };

    //mouse dragged event
    EventHandler<MouseEvent> mouseDragged = new EventHandler<MouseEvent>()
    {
        @Override
        public void handle(MouseEvent e)
        {
            System.out.println(Math.hypot(line.getBoundsInLocal().getWidth(), line.getBoundsInLocal().getHeight()));

            System.out.println("dragged");
            double offSetX = e.getSceneX() - sceneX;
            double offSetY = e.getSceneY() - sceneY;

            Circle tempCircle = ((Circle) (e.getSource()));
            tempCircle.setCenterX(tempCircle.getCenterX() + offSetX);
            tempCircle.setCenterY(tempCircle.getCenterY() + offSetY);

            if (Math.hypot(line.getBoundsInLocal().getWidth(), line.getBoundsInLocal().getHeight()) >= 100) {
                tempCircle.setCenterX(tempCircle.getCenterX() - offSetX);
                tempCircle.setCenterY(tempCircle.getCenterY() - offSetY);
            }

            sceneX = e.getSceneX();
            sceneY = e.getSceneY();
        }
    };


    @Override
    public void start(Stage stage)
    {

        circle.setOnMouseDragged(mouseDragged);
        circle2.setOnMouseDragged(mouseDragged);

        Line returnLine = connectLines(line, circle, circle2);

        StackPane root = new StackPane(new Pane(circle, circle2, returnLine));

        stage.setTitle("TableView (o7planning.org)");

        Scene scene = new Scene(root, 450, 300);
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args)
    {
        launch(args);
    }
}


Share : facebook icon twitter icon
JavaFX load text with more lines in to javafx container

JavaFX load text with more lines in to javafx container


By : Paulo Cesar
Date : March 29 2020, 07:55 AM
it fixes the issue BufferedReader.readLine removes the line breaks. Just add the line breaks back in and use a TextArea:
code :
StringBuilder stringBuilder = new StringBuilder();
String text;
while ((text = bufferedReader.readLine()) != null) {
    stringBuilder.append(text).append("\n");
}
// set the text in the TextArea
your_text_area.setText(stringBuilder.toString());
JavaFX - Constraints in programmatically scrolling a ScrollPane

JavaFX - Constraints in programmatically scrolling a ScrollPane


By : Phoenixphile
Date : March 29 2020, 07:55 AM
With these it helps You need to set the Hvalue/Vvalue of the ScrollPane after the scene is visible i.e. stage.isShowing() is true.
EDIT
code :
public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        LineChart<Number, Number> chart = new LineChart<>(new NumberAxis(), new NumberAxis());
        ScrollPane scrollPane = new ScrollPane(chart);
        primaryStage.setScene(new Scene(scrollPane, 300, 300));
        primaryStage.show();
        scrollPane.setVvalue(0.5);
        scrollPane.setHvalue(0.5);
    }

    public static void main(String[] args) {
        launch(args);
    }
}
public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        LineChart<Number, Number> chart = new LineChart<>(new NumberAxis(), new NumberAxis());
        ScrollPane scrollPane = new ScrollPane(chart);
        primaryStage.setScene(new Scene(scrollPane, 300, 300));

        scrollPane.getScene().getWindow().showingProperty().addListener((observable, oldValue, newValue) -> {
            if (newValue) {
                scrollPane.setVvalue(0.5);
                scrollPane.setHvalue(0.5);
            }
        });
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}
Creating a loop for column & row constraints with JavaFX

Creating a loop for column & row constraints with JavaFX


By : Ixchel Beristain
Date : March 29 2020, 07:55 AM
may help you . For my highscore window I have 20 nodes inside a gridpane (20 labels). Now I want the gridpane to be as big as the window itself which is 450 x 450, and I was planning to do this by adding column & row constraints. , if you define an array you have to initiate it and set a size.
code :
private ColumnConstraints[] columnConstraintses = new ColumnConstraints[10];
private RowConstraints[] rowConstraintses = RowConstraints[10];
Javafx Scrollpane Constraints when inside another Pane

Javafx Scrollpane Constraints when inside another Pane


By : Marta Chupil
Date : March 29 2020, 07:55 AM
it helps some times Pane simply resizes the children to the preferred size and keeps the position. This means no resizing is applied. Also it does not offer any further layout constraints.
You could simply replace the parent pane with a AnchorPane and the anchors become available again.
JavaFX ScrollPane not fitting its constraints

JavaFX ScrollPane not fitting its constraints


By : Йожжж
Date : March 29 2020, 07:55 AM
wish helps you I want to achieve the results like the blow image where the scroll bar always stays close to the go button. , Try the following:
code :
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>

<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: white;" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ResultsUI">
   <children>
      <AnchorPane prefWidth="600.0" style="-fx-background-color: white;" VBox.vgrow="NEVER">
         <children>
            <TextField id="queryOldTF" fx:id="queryOldTF" layoutX="14.0" layoutY="14.0" prefHeight="40.0" prefWidth="518.0" style="-fx-min-height: 40; -fx-border-radius: 50%; -fx-border-color: #007BFF; -fx-background-color: white;" AnchorPane.bottomAnchor="14.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="68.0" AnchorPane.topAnchor="14.0" />
            <Button id="serachAgainBtn" fx:id="serachAgainBtn" layoutX="532.0" layoutY="14.0" mnemonicParsing="false" onAction="#searchAgain" style="-fx-background-color: #007BFF; -fx-min-height: 40; -fx-min-width: 40; -fx-text-fill: white; -fx-border-radius: 50%; -fx-background-radius: 50%;" text="GO" AnchorPane.rightAnchor="14.0" AnchorPane.topAnchor="14.0" />
         </children>
         <VBox.margin>
            <Insets />
         </VBox.margin>
      </AnchorPane>
      <AnchorPane prefHeight="700.0" prefWidth="600.0" style="-fx-background-color: white;" VBox.vgrow="ALWAYS">
         <children>
            <ScrollPane id="scrollPane" fx:id="scrollPane" fitToWidth="true" layoutX="1.0" prefHeight="339.0" prefWidth="574.0" style="-fx-background-color: white;" vbarPolicy="ALWAYS" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="1.0" AnchorPane.rightAnchor="1.0" AnchorPane.topAnchor="0.0">
              <content>
                  <Pane style="-fx-background-color: white;">
                     <children>
                        <AnchorPane layoutX="10.0" layoutY="14.0" style="-fx-background-color: white;">
                           <children>
                              <Label id="descTl" layoutY="44.0" prefHeight="83.0" prefWidth="556.0" text="Description" AnchorPane.bottomAnchor="40.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="1.0" AnchorPane.topAnchor="40.0" />
                              <Label id="nameTl" prefHeight="27.0" prefWidth="557.0" style="-fx-font-size: 18;" text="Name" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="1.0" AnchorPane.topAnchor="1.0" />
                              <Label id="authorTl" layoutX="4.0" layoutY="27.0" prefHeight="17.0" prefWidth="413.0" text="Authors" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="1.0" />
                              <Button id="openBtn" layoutX="6.0" layoutY="135.0" mnemonicParsing="false" style="-fx-background-color: white; -fx-border-color: #007BFF; -fx-border-radius: 25%;" text="Open" AnchorPane.bottomAnchor="1.0" AnchorPane.rightAnchor="505.40000000000003" />
                           </children>
                        </AnchorPane>
                     </children>
                  </Pane>
              </content>
               <padding>
                  <Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
               </padding>
            </ScrollPane>
         </children>
      </AnchorPane>
   </children>
</VBox>
Related Posts Related Posts :
  • SpringBoot : No matching bean found exception
  • Implementing the Clonable interface, but don't have to override the clone() method
  • how can i get this code to choose a random word once from each array to print a sentence?
  • Static class to get connections from connection pool
  • Unable to start Chrome browser with user profile in Selenium
  • How to pass a object to be created as a parameter for a method in Java?
  • How to retry with hystrix
  • Loading key to KeyStore fails on Android Oreo
  • Spring+Velocity unsuccessful attempts to save object
  • Private constructor in Kotlin
  • Jetty:run fails with NoSuchMethodError with Spring 5
  • Cannot upload my Web Applicartion in Jboss7 EAP7 EAP
  • How to load a certificate from "Credential storage"?
  • Call Genexus procedure stub in Java environment
  • JavaFX clipping produces a 'lottery scratch ticket'-Effect
  • Using DateTimeFormatter on january first cause an invalid year value
  • Get all the output from Watson conversation using java
  • Java unable to open main class and jar file
  • How to override @override method from activity into another class
  • Adding Runtime VM parameters to intellij for Java 9
  • Java IBM MQ Client connected but not getting messages from queue
  • Questions of Tomcat SSL configuration
  • Stale JNLP files for <extension> (since Java 9?)
  • Properly set (system) properties in JUnit 5
  • Spring MVC Model within POST Method is empty
  • VSTS buildagent: Java 9
  • java.lang.NumberFormatException: For input string: "id" for Hibernate
  • Query id return type
  • Pass variable in API url in java .
  • Reading semicolon delimited csv
  • Get the workspace root
  • Native mmap error
  • hashmap and multiple txt files java
  • Kotlin: Access nested enum class from java
  • Google RateLimiter not Working for counter
  • Spring Boot Application Hanging When Running on Command Line
  • large amount of if else refactor
  • Unable to add xmlunit as dependancy in my pom
  • Scanner input needed twice, when only wanted once
  • How to interpret and translate kotlin code to java?
  • Firebase authentication: signInWithEmailAndPassword method dont respond at all
  • How Remove Recycler Separator/divider programmatically or using xml property
  • Not Able to Save Data Hibernate
  • Toolbar addView not working
  • Freeing memory wrapped with NewDirectByteBuffer
  • Synchronization with implicitwait() do not work, why?
  • Wrapper around Java primitive types
  • ClassNotFoundException: spark.Request when running from command line
  • Exception in Hibernate Configuration
  • How can I validate XML embedded in JSON using Citrus framework?
  • How is the String value passed to the updateText() method?
  • Memory efficient replace functions
  • Upload Photo with onActivityResult, but without Fullscreen capturing
  • Docker: Java 8 installation failing on Ubuntu
  • Java Netbeans Calculator performing wrong calculation
  • Nifi: Threads in nifi
  • While loop Int return inside the method completely dead
  • Checking if a user's entry is an integer using try catch statements
  • Forcing a subclass to provide an initialization method
  • calling a fuction and variables from another class in java
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org