0

Here is my code :

Button start = new Button("Start");
 start.setPrefHeight(100d);
 start.setMaxWidth(Double.MAX_VALUE); 
 start.setOnMouseClicked(new EventHandler<MouseEvent>(){
 @Override
 public void handle(MouseEvent arg0) {
 //ss.startServer();
 System.out.println("adfasddasfrwgafsdasdf");
 }
 });

The message does not get printed on the console at eclipse! I want the event to trigger when the mouse is released. What am I doing wrong?

Upon furthet investagation I realised that if I have another mouseReleased event on another node , it will fire more events!... why is that? For example , here is the code I am using, when I press the start button , it prints Start and Reload!

 start.setOnMouseReleased(new EventHandler<MouseEvent>(){
 @Override
 public void handle(MouseEvent arg0) {
 ss.startServer();
 System.out.println("Start");
 arg0.consume();
 }
 });
 Button stop = new Button("Stop");
 stop.setPrefHeight(100d);
 stop.setMaxWidth(Double.MAX_VALUE);
 stop.setOnMouseReleased(new EventHandler<MouseEvent>(){
 @Override
 public void handle(MouseEvent event) {
 sc.stopServer();
 System.out.println("Stop");
 event.consume();
 }
 });
 Button reload = new Button("Reload");
 reload.setPrefHeight(100d);
 reload.setMaxWidth(Double.MAX_VALUE);
 start.setOnMouseReleased(new EventHandler<MouseEvent>(){
 @Override
 public void handle(MouseEvent some) {
 sc.reloadServer();
 System.out.println("Reload");
 some.consume();
 }
 });

Stop button works properly! Anyway , if the other piece of code works , here it is(http://pastebin.com/4f55R2gN)

asked Nov 29, 2013 at 13:57

2 Answers 2

1

You typo'd your code. You set your MouseReleased handler on the start object instead of reload.

 Button reload = new Button("Reload");
 reload.setPrefHeight(100d);
 reload.setMaxWidth(Double.MAX_VALUE);
 start.setOnMouseReleased(new EventHandler<MouseEvent>(){
answered Nov 30, 2013 at 3:04
Sign up to request clarification or add additional context in comments.

Comments

1

Try this

button.setOnMouseReleased(new EventHandler<MouseEvent>() {
 @Override
 public void handle(MouseEvent arg0) {
 System.out.println("button click and mouse released");
 }
});

The below works for me fine.

public class FxmlSample extends Application{
 public static void main(String[] args) {
 launch(args);
 }
 @Override
 public void start(Stage stage) throws IOException{
 JFrame frame = new JFrame();
 JFXPanel jfxPanel = new JFXPanel();
 Pane pane = new Pane();
 VBox vBox = new VBox();
 Button button = new Button("Click me");
 button.setMinSize(50.0, 50.0);
 button.setOnMouseReleased(new EventHandler<MouseEvent>() {
 @Override
 public void handle(MouseEvent arg0) {
 System.out.println("11111111111111");
 }
 });
 Button button_2 = new Button("Click me 2");
 button_2.setMinSize(50.0, 50.0);
 button_2.setOnMouseReleased(new EventHandler<MouseEvent>() {
 @Override
 public void handle(MouseEvent arg0) {
 System.out.println("2222222222222");
 }
 });
 vBox.setPadding(new Insets(20));
 vBox.getChildren().addAll(button, button_2);
 pane.getChildren().addAll(vBox);
 Scene scene = new Scene(pane); 
 jfxPanel.setScene(scene);
 frame.add(jfxPanel);
 frame.setVisible(true);
 frame.setMinimumSize(new Dimension(700, 700));
 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 }
}
answered Nov 29, 2013 at 14:27

1 Comment

Take a look at my full code here : pastebin.com/4f55R2gN I dont get it. it should work fine

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.