Forum Stats

  • 3,838,287 Users
  • 2,262,351 Discussions
  • 7,900,576 Comments

Discussions

Close "x" and minimize "-" on SplitPane

acepsut
acepsut Member Posts: 98
edited Feb 18, 2014 12:27PM in JavaFX 2.0 and Later

With this code I add a circle with an "x" to perform remove pane in a SplitPane, and add a circle with a "-" to perform a different divider position.

What I should get is one "x" and one "-", while now I have two "x" and two "-" overlap.

http://s30.postimg.org/sp7g8kaqp/Z896.png

What's wrong with this code?

class CustomTools extends Group {  
    public CustomTools() {  


        final Circle closeButton = CircleBuilder.create()  
                .centerX(5)  
                .centerY(0)  
                .radius(8)  
                .fill(Color.TRANSPARENT)
                .build();  


        final Text closeText = new Text(1, 3, "x");
        closeText.setFont(Font.font("Comic Sans MS", 12));


        final Circle minimizeButton = CircleBuilder.create()  
                .centerX(5)  
                .centerY(0)  
                .radius(8)  
                .fill(Color.TRANSPARENT)
                .build(); 


        final Text minimizeText = new Text(1, 3, "-");
        minimizeText.setFont(Font.font("Comic Sans MS", 12));


        closeButton.setOnMouseEntered(new EventHandler<MouseEvent>(){
            @Override
            public void handle(MouseEvent me){
                closeButton.setFill(Color.RED);
                closeButton.setOpacity(0.50);
                closeText.setFill(Color.WHITE);
            }
        });


        closeButton.setOnMouseExited(new EventHandler<MouseEvent>(){
            @Override
            public void handle(MouseEvent me){


                closeButton.setFill(Color.TRANSPARENT);
                closeText.setFill(Color.BLACK);
            }
        });


        minimizeButton.setOnMouseEntered(new EventHandler<MouseEvent>(){
            @Override
            public void handle(MouseEvent me){
                minimizeButton.setFill(Color.RED);
                minimizeButton.setOpacity(0.50);
                minimizeText.setFill(Color.WHITE);
            }
        });


        minimizeButton.setOnMouseExited(new EventHandler<MouseEvent>(){
            @Override
            public void handle(MouseEvent me){


                minimizeButton.setFill(Color.TRANSPARENT);
                minimizeText.setFill(Color.BLACK);
            }
        });


        getChildren().addAll(minimizeButton, minimizeText, closeButton, closeText);  
    }  
} 


    for (int i = 0; i < taToolsList.size(); i++) {
        ind = taToolsList.get(i);


        if (ind.getChart().chrt != null) {
            chrt = ind.getChart().chrt;


            final CustomPane testPane = new CustomPane();
            final SplitPane slp = chrt.getIntWindSplitPane();
            Label indicatorLabel = new Label("Indicator");
            indicatorLabel.setLayoutX(10);
            indicatorLabel.setLayoutY(8);
            indicatorLabel.setFont(Font.font("Verdana", 11));
            indicatorLabel.setTextFill(Color.BLACK);
            indicatorLabel.setOpacity(0.8);


            CustomTools ce = new CustomTools();
            ce.setOnMouseClicked(new EventHandler<MouseEvent>() {
                @Override
                public void handle(MouseEvent event) {
                    slp.getItems().remove(testPane);
                }
            });


            CustomTools cm = new CustomTools();
            cm.setOnMouseClicked(new EventHandler<MouseEvent>() {
                @Override
                public void handle(MouseEvent event) {
                    slp.setDividerPosition(0, 0.90);
                }
            });


            testPane.getChildren().addAll(ce, cm, indicatorLabel);


            ce.translateXProperty().bind(testPane.widthProperty().subtract(15));
            ce.setTranslateY(10);


            cm.translateXProperty().bind(testPane.widthProperty().subtract(30));
            cm.setTranslateY(10);


            slp.setDividerPosition(0, 0.70);
            slp.getItems().add(testPane);


        }
    }
Tagged:

Answers

  • 1060225
    1060225 Member Posts: 69
    edited Feb 18, 2014 10:55AM

    Could you please paste the complete code. I would like to test it.

  • acepsut
    acepsut Member Posts: 98

    This code is within a button.setOnAction method: I can't paste the whole code since some nodes are in different classes.

    To test this part, simply create a

    final SplitPane slp = new SplitPane(); instead of final SplitPane slp = chrt.getIntWindSplitPane();

    and

    final Pane testPane = new  Pane(); instead of final CustomPane testPane = new CustomPane();

  • acepsut
    acepsut Member Posts: 98

    Here is a sample code for testing

    import javafx.scene.text.Font;
    import javafx.application.Application; 
    import javafx.event.EventHandler; 
    import javafx.geometry.Orientation; 
    import javafx.scene.Group;  
    import javafx.scene.Scene; 
    import javafx.scene.control.Label; 
    import javafx.scene.control.SplitPane; 
    import javafx.scene.input.MouseEvent; 
    import javafx.scene.layout.Pane; 
    import javafx.scene.paint.Color; 
    import javafx.scene.shape.Circle; 
    import javafx.scene.shape.CircleBuilder; 
    import javafx.scene.text.Text; 
    import javafx.stage.Stage; 
    
    
    public class ClosableSplitPane extends Application { 
        @Override 
        public void start(Stage primaryStage) { 
           
            Pane root = new Pane(); 
            final SplitPane sp = new SplitPane(); 
            sp.setPrefSize(800, 650); 
            final Pane paneOne = new Pane(); 
            final Pane paneTwo = new Pane(); 
            final Pane paneThree = new Pane(); 
            final Pane paneFour = new Pane(); 
          
            CustomExit ceTwo = new CustomExit(); 
            ceTwo.setOnMouseClicked(new EventHandler<MouseEvent>() { 
                @Override 
                public void handle(MouseEvent event) { 
                    sp.getItems().remove(paneTwo); 
                } 
            }); 
           
            CustomExit meTwo = new CustomExit(); 
            meTwo.setOnMouseClicked(new EventHandler<MouseEvent>() { 
                @Override 
                public void handle(MouseEvent event) { 
                    sp.getItems().remove(paneTwo); 
                } 
            }); 
           
            paneTwo.getChildren().addAll(ceTwo, meTwo); 
            ceTwo.translateXProperty().bind(paneTwo.widthProperty().subtract(15)); 
            ceTwo.setTranslateY(10); 
            meTwo.translateXProperty().bind(paneTwo.widthProperty().subtract(25)); 
            meTwo.setTranslateY(10);
           
            CustomExit ceThree = new CustomExit(); 
            ceThree.setOnMouseClicked(new EventHandler<MouseEvent>() { 
                @Override 
                public void handle(MouseEvent event) { 
                    sp.getItems().remove(paneThree); 
                } 
            }); 
           
            paneThree.getChildren().addAll(ceThree); 
            ceThree.translateXProperty().bind(paneThree.widthProperty().subtract(15)); 
            ceThree.setTranslateY(10); 
           
            CustomExit ceFour = new CustomExit(); 
            ceFour.setOnMouseClicked(new EventHandler<MouseEvent>() { 
                @Override 
                public void handle(MouseEvent event) { 
                    sp.getItems().remove(paneFour); 
                } 
            }); 
           
            paneFour.getChildren().addAll(ceFour); 
            ceFour.translateXProperty().bind(paneFour.widthProperty().subtract(15)); 
            ceFour.setTranslateY(10); 
           
            Label labelFirst = new Label(" Pane One"); 
            Label labelSecond = new Label(" Pane Two"); 
            Label labelThird = new Label(" Pane Three"); 
           
            paneTwo.getChildren().add(labelFirst); 
            paneThree.getChildren().add(labelSecond); 
            paneFour.getChildren().add(labelThird); 
           
            sp.setDividerPositions(0.5f, 0.65f, 0.8f); 
            sp.getItems().addAll(paneOne, paneTwo, paneThree, paneFour); 
            sp.setVisible(true); 
            sp.setOrientation(Orientation.VERTICAL); 
           
            root.getChildren().add(sp); 
            Scene scene = new Scene(root, 800, 650); 
            primaryStage.setTitle("Closable SplitPane"); 
            primaryStage.setScene(scene); 
            primaryStage.show(); 
        } 
       
        public static void main(String[] args) { 
            launch(args); 
        } 
       
        class CustomExit extends Group { 
            public CustomExit() { 
               
                final Circle closeButton = CircleBuilder.create() 
                        .centerX(5) 
                        .centerY(0) 
                        .radius(7) 
                        //.fill(Color.rgb(100, 100, 100, .40))
                        .fill(Color.TRANSPARENT)
                        .build(); 
               
                final Text closeText = new Text(1, 3, "x");
                closeText.setFont(Font.font("Comic Sans MS", 12));
               
                closeButton.setOnMouseEntered(new EventHandler<MouseEvent>(){
                    @Override
                    public void handle(MouseEvent me){
                        closeButton.setFill(Color.RED);
                        closeButton.setOpacity(0.40);
                        closeText.setFill(Color.WHITE);
                    }
                });
               
                closeButton.setOnMouseExited(new EventHandler<MouseEvent>(){
                    @Override
                    public void handle(MouseEvent me){
                       //closeButton.setFill(Color.rgb(100, 100, 100));
                        closeButton.setFill(Color.TRANSPARENT);
                        closeText.setFill(Color.BLACK);
                    }
                });
               
                final Circle minimizeButton = CircleBuilder.create() 
                        .centerX(5) 
                        .centerY(0) 
                        .radius(7) 
                        //.fill(Color.rgb(100, 100, 100, .40))
                        .fill(Color.TRANSPARENT)
                        .build(); 
               
                final Text minimizeText = new Text(1, 3, "-");
                minimizeText.setFont(Font.font("Comic Sans MS", 12));
               
                minimizeButton.setOnMouseEntered(new EventHandler<MouseEvent>(){
                    @Override
                    public void handle(MouseEvent me){
                        closeButton.setFill(Color.RED);
                        closeButton.setOpacity(0.40);
                        closeText.setFill(Color.WHITE);
                    }
                });
               
                minimizeButton.setOnMouseExited(new EventHandler<MouseEvent>(){
                    @Override
                    public void handle(MouseEvent me){
                       //closeButton.setFill(Color.rgb(100, 100, 100));
                        closeButton.setFill(Color.TRANSPARENT);
                        closeText.setFill(Color.BLACK);
                    }
                });
    
    
                getChildren().addAll(closeButton, closeText, minimizeButton, minimizeText); 
            } 
        } 
    } 
    
This discussion has been closed.