Skip to content

Instantly share code, notes, and snippets.

@komax
Created July 5, 2013 11:07
Show Gist options
  • Save komax/5933828 to your computer and use it in GitHub Desktop.
Save komax/5933828 to your computer and use it in GitHub Desktop.
require 'java'
require 'jrubyfx'
JavaFX = Java::javafx
class FormApp < JRubyFX::Application
def start(stage)
stage.set_title("JavaFX Welcome")
grid = JavaFX::scene.layout.GridPane.new
grid.alignment = JavaFX.geometry.Pos::CENTER
grid.hgap = 10
grid.vgap = 10
grid.padding = JavaFX.geometry.Insets.new(25, 25, 25, 25)
scenetitle = JavaFX.scene.text.Text.new("Welcome")
scenetitle.font = JavaFX.scene.text.Font.font("Tahoma",
JavaFX.scene.text.FontWeight::NORMAL, 20)
grid.add(scenetitle, 0, 0, 2, 1)
user_name = JavaFX.scene.control.Label.new("User Name:")
grid.add(user_name, 0, 1)
user_text_field = JavaFX.scene.control.TextField.new
grid.add(user_text_field, 1, 1)
pw = JavaFX::scene::control::Label.new("Password:")
grid.add(pw, 0, 2)
pw_box = JavaFX::scene::control::PasswordField.new
grid.add(pw_box, 1, 2)
# for debugging: shows spaces between added Controls
grid.grid_lines_visible = true
button = JavaFX::scene::control::Button.new("Sign in")
hbox_button = JavaFX::scene::layout::HBox.new(10)
hbox_button.alignment = JavaFX::geometry::Pos::BOTTOM_RIGHT
hbox_button.children.add(button)
grid.add(hbox_button, 1, 4)
actiontarget = JavaFX::scene::text::Text.new
grid.add(actiontarget, 1, 6)
button.set_on_action do
#puts "foo"
actiontarget.fill = JavaFX::scene::paint::Color::FIREBRICK
actiongarget.text = "Sign in button pressed"
end
scene = JavaFX.scene.Scene.new(grid, 300, 275)
stage.scene = scene
stage.show
end
end
FormApp.launch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment