Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
JRuby/SWTSnippets/Snippet6.rb
< JRuby | SWTSnippets
################################################################################ # Copyright (c) 2009 IBM Corporation and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at # http://www.eclipse.org/legal/epl-v10.html # # Contributors: # IBM Corporation - initial API and implementation ################################################################################ require 'java' # # GridLayout example snippet: insert widgets into a grid layout # # For a list of SWT example snippets ported to JRuby, see # http://wiki.eclipse.org/JRuby/SWTSnippets # # @since 3.1 # class Snippet6 include_package 'org.eclipse.swt' include_package 'org.eclipse.swt.layout' include_package 'org.eclipse.swt.widgets' def self.main display = Display.new shell = Shell.new(display) shell.setLayout(GridLayout.new) c = Composite.new(shell, SWT::NONE) layout = GridLayout.new layout.numColumns = 3 c.setLayout(layout) 10.times do |i| b = Button.new(c, SWT::PUSH) b.setText("Button #{i}") end b = Button.new(shell, SWT::PUSH) b.setText("add a new button at row 2 column 1") index = 0 b.addListener(SWT::Selection) do s = Button.new(c, SWT::PUSH) s.setText("Special #{index}") index += 1 children = c.getChildren s.moveAbove(children[3]) shell.layout([s].to_java Control) end shell.open display.sleep unless display.readAndDispatch until shell.disposed display.dispose end end Snippet6.main
Compare with the Java version.