Skip to content

Instantly share code, notes, and snippets.

@retorquere
Created January 31, 2013 00:50
Show Gist options
  • Save retorquere/4678888 to your computer and use it in GitHub Desktop.
Save retorquere/4678888 to your computer and use it in GitHub Desktop.
Tree drag and drop
#!/usr/bin/env jruby
require 'jrubyfx'
java_import 'javafx.scene.control.TreeCell'
class MyTreeCell < TreeCell
def updateItem(item, empty)
super(item, empty)
text = item unless item
end
end
class Hello < JRubyFX::Application
def start(stage)
with(stage, title: "Hello Devoxx", x: 105, y: 140) do
layout_scene(500, 250, :black) do
hbox(padding: insets(60)) do
root = tree_item("Root")
1.upto(5) {|i|
root.children.add(tree_item("File #{i}"))
}
tree_view(root) do
set_cell_factory do
MyTreeCell.new.tap do |tree_cell|
tree_cell.set_on_drag_detected do |mouse_event|
# ...
end
end
end
end
end
end
show
end
end
end
Hello.launch
@enebo
Copy link

enebo commented Jan 31, 2013

#!/usr/bin/env jruby

require 'jrubyfx'

java_import 'javafx.scene.control.TreeCell'

class MyTreeCell < TreeCell
  def updateItem(item, empty)
    super(item, empty)
    self.text = item if item
  end
end

class Hello < JRubyFX::Application
  def start(stage)
    with(stage, title: "Hello Devoxx", x: 105, y: 140) do
      layout_scene(500, 250, :black) do
        hbox(padding: insets(60)) do
          tree_view do
            tree_item("Root") do
              5.times {|i| tree_item("File #{i}") }
            end
            set_cell_factory do
              MyTreeCell.new.tap do |tree_cell|
                tree_cell.set_on_drag_detected do |mouse_event|
                  puts "MOUUSE #{mouse_event}"
                  # ...
                end
              end
            end
          end
        end
      end
      show
    end
  end
end

Hello.launch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment