Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Mirah/SWTSnippets/Snippet6"

Line 23: Line 23:
  
 
display = Display.new
 
display = Display.new
shell = Shell.new(display)
+
shell = Shell.new display
shell.setLayout(GridLayout.new)
+
shell.setLayout GridLayout.new
c = Composite.new(shell, SWT.NONE)
+
c = Composite.new shell, SWT.NONE
 
layout = GridLayout.new
 
layout = GridLayout.new
 
layout.numColumns = 3
 
layout.numColumns = 3
c.setLayout(layout)
+
c.setLayout layout
 
10.times do |i|
 
10.times do |i|
b = Button.new(c, SWT.PUSH)
+
b = Button.new c, SWT.PUSH
b.setText("Button #{i}")
+
b.setText "Button #{i}"
 
end
 
end
b = Button.new(shell, SWT.PUSH)
+
b = Button.new shell, SWT.PUSH
b.setText("add a new button at row 2 column 1")
+
b.setText "add a new button at row 2 column 1"
 
index = 1
 
index = 1
 
b.addListener(SWT.Selection) do |e|
 
b.addListener(SWT.Selection) do |e|
s = Button.new(c, SWT.PUSH)
+
s = Button.new c, SWT.PUSH
s.setText("Special #{index}")
+
s.setText "Special #{index}"
 
index += 1
 
index += 1
children = c.getChildren()
+
children = c.getChildren
s.moveAbove(children[3])
+
s.moveAbove children[3]
 
toLayout = Control[1]
 
toLayout = Control[1]
 
toLayout[0] = s
 
toLayout[0] = s
shell.layout(toLayout)
+
shell.layout toLayout
 
end
 
end
 
shell.open
 
shell.open
while !shell.isDisposed
+
until shell.isDisposed
if !display.readAndDispatch
+
unless display.readAndDispatch
 
display.sleep
 
display.sleep
 
end
 
end

Revision as of 10:21, 27 March 2011

/*******************************************************************************
 * Copyright (c) 2000, 2011 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
 *******************************************************************************/

/*
 * GridLayout example snippet: insert widgets into a grid layout
 *
 * For a list of SWT example snippets ported to Mirah, see
 * http://wiki.eclipse.org/Mirah/SWTSnippets
 * 
 * @since 3.1
 */
import org.eclipse.swt.*
import org.eclipse.swt.layout.*
import org.eclipse.swt.widgets.*

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 = 1
b.addListener(SWT.Selection) do |e|
	s = Button.new c, SWT.PUSH
	s.setText "Special #{index}"
	index += 1
	children = c.getChildren
	s.moveAbove children[3]
	toLayout = Control[1]
	toLayout[0] = s
	shell.layout toLayout
end
shell.open
until shell.isDisposed
	unless display.readAndDispatch
		display.sleep
	end
end
display.dispose

Back to the top