Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Redraw Issues on Shapes with FX

  1. #1
    Junior Member
    Join Date
    Mar 2018
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Redraw Issues on Shapes with FX

    Hello

    Trying to get a circle to automatically re-adjust its radius depending on what the user puts in the text field. There are no syntax error and the code compiles but nothing has rendered. The text is to stay inside the circle. Also kept getting error reference to another code but that may have been just that compiler.

    import javafx.application.Application;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;
    import javafx.scene.control.TextField;
    import javafx.geometry.Pos;
    import javafx.scene.text.Font;
    import javafx.scene.shape.*;
    import javafx.scene.Group;
    import javafx.scene.control.Label;
    import javafx.scene.layout.GridPane;
    import javafx.geometry.HPos;
    import java.util.Scanner;
     
    public class PP4o15 extends Application {
        private Label result;
        private TextField input;
     
        public void start(Stage primaryStage) {
            int r;
            double pi= 3.14, area;
            Circle circle= new Circle(100,65,20);
            circle.setFill(null);
     
     
            Scanner q = new Scanner(System.in);
            r=q.nextInt();
            //Pi Method
            area=pi*r*r;
     
     
            Font font= new Font(18);
            input= new TextField();
            //Changed Font below
            input.setFont(new Font("Arial",30));
            input.setPrefWidth(50);
            input.setAlignment(Pos.CENTER);
     
            //Stacking input TextField ontop of circle
            //StackPane pane= new StackPane(circle);
            //pane.getChildren().addAll(circle,input);
     
            Group root= new Group(circle);
            Scene scene= new Scene(root,400,200);
     
            result = new Label("");
            result.setFont(font);
            GridPane.setHalignment(result,HPos.CENTER);
     
            primaryStage.setTitle("Enter in Radius");
            primaryStage.setScene(scene);
            primaryStage.show();
        }
        //Create method that has return
        public void processReturn(ActionEvent event)
        {
           //Method to process return
            input.setOnAction(this::processReturn); 
        }
    }

  2. #2
    Member
    Join Date
    Apr 2014
    Posts
    75
    Thanks
    2
    Thanked 6 Times in 6 Posts

    Default Re: Redraw Issues on Shapes with FX

    First, the circle will need a fill that is non-null:
    circle.setFill(Color.RED);
    Then you've asked the user for the radius but didn't do anything with it:
    r = q.nextInt();
    circle.setRadius(r); // <<<<<< Add this!
    Good luck!

Similar Threads

  1. [SOLVED] JTable won't redraw unti i resize the window
    By shadowfiend in forum AWT / Java Swing
    Replies: 6
    Last Post: September 4th, 2014, 10:21 AM
  2. 3D shapes with java
    By Zuckerberg in forum What's Wrong With My Code?
    Replies: 8
    Last Post: February 19th, 2014, 11:05 PM
  3. Showing Shapes
    By marc172 in forum AWT / Java Swing
    Replies: 1
    Last Post: January 27th, 2014, 07:27 AM
  4. Issues with my ordering program - if statement issues?
    By Shenaniganizer in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 31st, 2012, 10:17 PM
  5. Combining Shapes + Text
    By aussiemcgr in forum Java Theory & Questions
    Replies: 5
    Last Post: February 17th, 2011, 09:15 AM