• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

How do I get the buttons Add, Subtract, Multiply and Divide close to each other? im Completely lost  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 //Create buttons (Add, Subtract, Multiply and Divide)
   private Button Add = new Button ("ADD");
   private Button Subtract = new Button ("SUBTRACT");
   private Button Multiply = new Button ("MULTIPLY");
   private Button Divide = new Button ("DIVIDE");
 
   @Override
   public void start (Stage primaryStage){
     
   
  GridPane pane = new GridPane ();
   HBox buttons = new HBox();
         
   //Text fields
   //Text Field 1
   pane.add(new Label ("Enter #1: "),1, 1);
   TextField txtNum1 = new TextField();
   //Text Field 2
   pane.add(new Label ("Enter #2 :"), 2, 1);
   TextField txtNum2 = new TextField();
   //Result
   pane.add(new Label("Result:"), 3, 1);
   TextField Result = new TextField();
   pane.setAlignment(Pos.CENTER);
   pane.setStyle("-fx-background-color: lightPink");
     
   
   //add buttons (Add, Subtract, Multiply and Divide)
   
   pane.add(Subtract, 1, 5);
   pane.add(Multiply, 2, 5);
   pane.add(Divide, 3, 5);
   pane.add(txtNum1, 1, 0);
   pane.add(txtNum2, 2,0);
   pane.add(Result, 3,0);
   
   
 
   //Perform computations
   //Result is equal to txtNum1 + txtNum2
   //Result is equal to txtNum1 - txtNum2
   //Result is equal to txtNum1 * txtNum2
   //Result is equal to txtNum1 / txtNum2
   
   
   //create a scene and add it to the screen  
   Scene scene = new Scene(pane,600, 150);
      primaryStage.setTitle("Calculator");
      primaryStage.setScene(scene);
      primaryStage.show();
   }
     public static void main(String[] args) {
      launch (args);
 
Rancher
Posts: 427
6
Fedora IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is what you have now doing?
 
Marshal
Posts: 5988
155
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You haven't given us much to work with.  First, you posted code without tags.  Always UseCodeTags (that's a link).

Second, you didn't post all of the class.  I pieced it together but a lot of people won't take the time to do that.

Third, the code is not formatted well.

Here is how you should have posted the code:
I've attached a screenshot of what the above class produced.  

If you want the buttons in a more traditional setting, try adding a ButtonBar under the GridPane.  Both should go in a VBox.
CalculatorScreenShot.png
[Thumbnail for CalculatorScreenShot.png]
Calculator
 
Brace yourself while corporate america tries to sell us its things. Some day they will chill and use tiny ads.
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!