[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.36 Swing support

Procedures for constructing a GUI with Swing.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.36.1 Generic components

Function: get-gui-element-width gui-component

gets width of the GUI component.

Function: get-gui-element-height gui-component

gets height of the GUI component.

Function: set-background-color! gui-component color

sets color of the component to the given color.

Function: set-preferred-width! gui-component width

gets preffered width of the GUI component.

Function: set-preferred-height! gui-component height

gets preffered height of the GUI component.

Function: get-bounds-x gui-component

gets X-coordinate of the component.

Function: get-bounds-y gui-component

gets Y-coordinate of the component.

Function: set-bounds-x! gui-component x

sets X-coordinate of the component to the given number.

Function: set-bounds-y! gui-component y

sets Y-coordinate of the component to the given number.

Function: get-text has-text

gets a text from the component which has a text e.g. textfields.

Function: set-text! has-text str

sets the given text to the component which has a text.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.36.2 Buttons

Function: make-button text action

creates a button with the given text.
action specified the procedure with one argument when button is pressed.

Function: make-button-with-action accelerator-key: accelerator-key long-description: long-description mnemonic-key: mnemonic-key name: name short-description: short-description small-icon: small-icon

creates a button with an action.
Available actions show as follows.

actionspecify a procedure with one argument when the action is executed
accelerator-keyspecify an accelerator key
long-descriptionspecify a long description
mnemonic-keyspecify a mnemonic key
namespecify a name
short-descriptionspecify a short description
small-iconspecify a small icon

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.36.3 Canvases

Function: make-canvas [x-begin y-begin x-end y-end]

creates a canvas which can be painted by the painter framework.
Window coordinate can be specified with x-begin, y-begin, x-end and y-end. If you specify x-begin and so on coordinate system of the window has direction which is used in mathematics (x-axis is right directed and y-axis is up directed). If you don’t specify x-begin and so on coordinate system has direction which is used in computer graphics (x-axis is right directed and y-axis is down directed).


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.36.4 Labels

Function: make-label name

creates a label with the given name.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.36.5 Containers

Function: make-panel

creates a panel which can contain GUI components.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.36.6 Texts

Function: make-text-field size [text]

creates a textfield with the given size. Initial text can be specified with text.

Function: make-text-area [row-size column-size]

creates a text area with row-size and column-size.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.36.7 Windows

Function: make-window title [xsize ysize [menus]]

create a window with xsize and ysize. The window is not displayed when this procedure is executed.
menus specifies properties of menubar shown as follows.

("menu1" proc)a menu with procedure proc. proc has one argument.
("menu1" proc key key2)a menu with procedure proc and short cut keys.
("menu1" seperator)a menu separator.
("menu1" (submenu))a sub menu.
Function: show-window window

shows the window.

Function: hide-window window

hides the window.

Function: exec-window window

shows the window. Program exits when the window is closed.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.36.8 Dialogs

Function: make-modal-dialog parent-window title x y

creates a modal dialog component. The dialog is not displayed when this procedure is executed. Please use show-window.

Function: make-modeless-dialog parent-window title x y

creates a modeless dialog component. The dialog is not displayed when this procedure is executed. Please use show-window.

Function: show-yes-no-dialog parent-component message title message-type

shows a yes-no dialog and returns #t if the response is yes. parent-component specifies a parent component of the dialog or #f if no parent components specify.
message-type specifies a message type such as error, warning and information. Symbols shown as follows is available as message-type.

Function: show-yes-no-cancel-dialog parent-component message title message-type

shows a yes-no-cancel dialog and returns #t if the response is yes, #f if the response is no or symbol ’canceled if the dialog is canceled.

Function: show-input-dialog parent-component message title message-type

shows a input dialog and returns a string which is inputed or #f if the dialog is canceled.

Function: show-message-dialog parent-component message title message-type

shows a message dialog.

Function: set-dialog-resizable! dialog resize?

sets whether size of the dialog is variable.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.36.9 Comboboxes/listboxes

Function: make-combobox item-list

creates a combobox with item-list. A value of the combobox is editable.
item-list is an associative list whose element is (value to be displayed . value to be gotten by get-selected-item-value).

Function: make-listbox item-list

creates a listbox with item-list. A value of the listbox is not editable.
item-list is an associative list whose element is (value to be displayed . value to be gotten by get-selected-item-value).

Function: get-selected-item-value selectable

gets a value from the selectable component e.g. listbox and combobox.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.36.10 Checkboxes/radio buttons

Function: make-checkbox text

creates a checkbox component.

Function: checkbox-checked? checkbox

returns #t if the checkbox is checked.

Function: set-checkbox-checked! checkbox check

checks/unchecks the checkbox.

Function: make-radio-button text [action-proc]

creates a radio button component.
action-proc specifies a procedure with one argument.

Function: make-button-group radio-button-list

creates a button group. radio-button-list specifies buttons included in the group.

Function: get-selected-button-value button-group

returns a value which is selected in the button group.

Function: set-selected-button-value! button-group datum

changes the value which is selected in the button group.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.36.11 File choosers

Function: make-file-chooser extension-filters

creates a file chooser.
extension-filters specifies a list to be filtered. Syntax of extension-filters shows as follows.

(("extension[,extension …]" . a string to display the file chooser
 …)

The dialog is not displayed when this procedure is executed. Please call show-xxx-file-chooser.

Function: set-file-selection-mode! filechooser mode

changes the selection mode of the file chooser. Available modes are shown as follows.

filesfiles only
directoriesdirectories only
files-and-directoriesfiles and directories
Function: set-accept-all-file-filter-used! filechooser use?

sets whether "selects all files" is used as a filter.

Function: show-open-file-chooser filechooser parent-component

shows the filechooser as "open" and returns the chosen file or #f(canceled).

Function: show-save-file-chooser filechooser parent-component

shows the filechooser as "save" and returns the chosen file or #f(canceled).

Function: show-file-chooser filechooser parent-component approve-button-text

shows the filechooser whose button is specified by approve-button-text and returns the chosen file or #f(canceled).


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.36.12 Color choosers

Function: show-color-chooser [color] [parent-component]

shows a color chooser.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.36.13 Menus

Function: make-menu-item title action-proc [mnenomic-key mnenomic-key-modifier]

creates a menu item component.
action-proc specifies a procedure with one argument. mnenomic-key and mnenomic-key-modifier specify a mnenomic key.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.36.14 Clipboards

Function: copy-to-system-clipboard! datum

copies the object to the system clipboard.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.36.15 Scroll bars

Function: make-horizontal-scroll-bar value extent min max [real-min real-max]

creates a horizontal scroll bar component.
The arguements means shown as follows.

valueinitial value
extentstep
minmaximum
maxminimum
real-minscaled maximum
real-maxscaled minimum
Function: make-vertical-scroll-bar value extent min max [real-min real-max]

creates a vertical scroll bar component.

Function: get-scroll-bar-value scroll-bar

gets the value which the scroll bar indicates.

Function: get-scroll-bar-relative-value scroll-bar

gets the relative value which the scroll bar indicates. Its maximum is 1 and minimum is 0.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.36.16 Spinners

Function: make-number-spinner value min max step [format]

creates a number spinner component.
If max(min) is #f, there is no upper(lower) bound. The form of format is under java.text.DecimalFormat.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.36.17 Tabbed panes

Function: make-tabbed-pane component …

creates a tabbed pane.

Function: get-selected-tab tabbed-pane

gets the component which is selected in the tabbed pane.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.36.18 Icons

Function: make-image-icon image-file-name

creates an image icon.

Function: make-frame-icon width height [x-begin y-begin x-end y-end]

creates an icon which can be painted by the painter framework.
The coordinate can be specified with x-begin, y-begin, x-end and y-end. If you specify x-begin and so on coordinate system of the window has direction which is used in mathematics (x-axis is right directed and y-axis is up directed). If you don’t specify x-begin and so on coordinate system has direction which is used in computer graphics (x-axis is right directed and y-axis is down directed).

Coordinate which you specify is conserved when the window is resized.
The window is disposed when it is closed.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.36.19 Text pane

Function: make-text-pane

creates a text pane.

Function: set-default-key-action! text-pane action …

sets a default action when a key is pressed.

Function: add-key-action! text-pane key key-modifier action …

adds a key action when a key is pressed.

Function: set-style! text-pane offset length [[attribute-key attribute] …]

sets a style of characters between offset to offset + length.

Available symbols for attribute-key are shown as follows.

keyworddescription
font-familyspecifies a kind of font
font-sizespecifies size of font
boldspecifies bold
italicspecifies italic
underlinespecifies underline
strikespecifies strike
superscriptspecifies superscript
subscriptspecifies subscript
colorspecifies color
background-colorspecifies background color

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.36.20 Layouts

Function: layout-grid-bag panel constraint

layouts the panel by GridBagLayout.
Syntax of constraint is shown as follows.

(((GUI component [(attribute . value) …])
  …
 [((GUI component [(attribute . value) …])
  …)]
 …)

Available symbols as attribute are shown as follows.

attributedescription
weightxweight of component width of a cell
weightyweight of component height of a cell
fillspecify whether the component is extended. Symbol shown as follows are available.
nonenot extend
horizontalextends horizontally
verticalextends vertically
bothextends horizontally and vertically
gridxspecifies x-coordinate
gridwidthspecifies horizontal merged cells (same as colspan in <table> of HTML)
gridheightspecifies vertical merged cells (same as rowspan in <table> of HTML)
Function: layout-grid panel layout [xgap ygap]

layouts the panel by GridLayout.
Syntax of layout is shown as follows.

(((component-of-the-first-column component-of-the-second-column …) ; This is first row
 ((component-of-the-first-column component-of-the-second-column …) ;This is second row
 …)
Function: layout-border panel layout [xgap ygap]

layouts the panel by BorderLayout.
Components to be layouted is specified by layout as an associative list whose value is a component and key is shows as follows.

symbol of the keydescription
centercenter
northnorth
southsouth
easteast
westwest
Function: layout-flow component …

layouts the panel by FlowLayout.

Function: layout-group component layout

layouts the panel by GroupLayout.
Layout is specified by a list of components or a vector which specifies a gap.

Vertical gap is specified by #(vertical min prefer max) and horizontal gap is specified by #(horizontal min prefer max).

Here is an example.

(layout-group
  *window1*
  `((,a #(,b vertical 20 25 30))
    (,c ((,d ,e)
         (,f ,g)))
    (,h #(horizontal 5 10 20 vertical 20 25 30))))
Function: layout-null component layout

layouts the panel without any layout. This procedure should not use as possible.

This procedure layouts components with coordinates. Here is an example.

(layout-null
  *window1*
  `((,a 100 100 50 30)    ; x-coodinate y-coordinate width height
    (,b 200 200 100 20)))

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.36.21 Progress bars/monitors

Function: make-progress-bar [orientation] [max min]

creates a progress bar. orientation must be the symbol ’horizontal or ’vertical.

Function: prograss-bar-maximum progress-bar
Function: prograss-bar-minimum progress-bar

gets maximum(minimum) of the progress bar.

Function: progress-bar-value progress-bar

gets current value of the progress bar.

Function: progress-bar-percent-complete progress-bar

gets ratio of the progress bar.

Function: progress-bar-string progress-bar

gets the string which is displayed in the progress bar.

Function: progress-bar-orientation progress-bar

gets the orientation of the progress bar.

Function: prograss-bar-maximum-set! progress-bar value
Function: prograss-bar-minimum-set! progress-bar value

sets maximum(minimum) of the progress bar.

Function: progress-bar-value-set! progress-bar value

sets current value of the progress bar.

Function: progress-bar-string-set! progress-bar string

sets the string which is displayed in the progress bar.

Function: progress-bar-indeterminate-set! progress-bar

sets the indeterminate mode to the progress bar.

Function: make-progress-monitor millis component message note max min

creates a progress monitor.
The progress monitor is a dialog window which is not displayed initially but displayed when a process has not been terminated.
millis, component, message, note, max and min specify millisecond to display, a parent component(or #f), a note, maximum and minimum respectively.

Function: progress-monitor-progress-set! progress-monitor value

sets the progress value to the progress monitor.
The progress monitor is closed automatically when the value is more than its maximum.

Function: progress-monitor-note progress-monitor

gets the note of the progress monitor.

Function: progress-monitor-note-set! progress-monitor string

sets the note of the progress monitor.

Function: progress-monitor-close progress-monitor

closes the progress monitor.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.36.22 Swing lists

Function: make-jlist vector
Function: make-jlist list

creates a Swing list. Values of the list are specified by first argument.
When the argument is a vector, the Swing list is immutable.
When the argument is a Scheme list, the Swing list is mutable.

Function: jlist-selected-value-list jlist

gets a list of the objects which are selected in the Swing list.

Function: jlist-selection-mode-set! jlist mode

sets the selection mode of the Swing list. Symbols shown as follows are available as mode.

symboldescription
singleonly single value can be selected
intervalan interval of values can be selected
multiplemultiple values can be selected
Function: jlist-selection-mode jlist

gets the selection mode of the Swing list.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.36.23 Swing trees

Nodes(leaves) of the Swing tree consist of abstract node objects. Structure of the tree is changed by the abstract node object.

Function: make-jtree tree-structure

creates a Swing tree.
Initial tree structure is specified by a list or a vector.
When the argument is a vector, the structure is immutable. When the argument is a Scheme list, the structure is mutable.
Syntax of tree-structure is shown as follows.

(node
 (node leaf1
      leaf2
      (node subleaf1 subleaf2 subleaf3)
      leaf3)
 (node leaf1 leaf2))
Function: jtree-selected-last-path jtree

gets a node which includes the object which selected first.

Function: jtree-selected-last-paths jtree

gets a list of nodes which selected in the Swing tree.

Function: jtree-selected-path-list jtree

gets a path which includes the object which selected first.

Function: jtree-selected-path-lists jtree

gets a list of lists of paths which selected in the Swing tree.

Function: jtree-root jtree

gets the root object of the Swing tree.

Function: jtree-root-node jtree

gets the root node of the Swing tree.

Function: jtree-root-set! jtree tree-structure

sets the structure of the Swing tree.

Function: jtree-last-path-for-location jtree x y

gets the object which is in component coordinate (x, y), or returns #f if there is no objects in (x, y).

Function: jtree-path-list-for-location jtree x y

gets the path is in component coordinate (x, y), or returns #f if there is no objects in (x, y).

Function: jtree-renderer-set! jtree renderer

sets the Swing tree renderer to the Swing tree.
The Swing tree renderer enables displaying custom icons and so on.
Procedure renderer has six arguments, which are a label, a destination Swing tree, a boolean value whether a node is selected, a boolean value wheteer the node is expanded, a boolean value wheteer the node is a leaf and a boolean value wheteer the node is focused, respectively.
Here is an example of displaying other icon when the object of a node is an integer.

(jtree-renderer-set!
  tr
  (lambda (l t node sel expn leaf hasf)
    (if (integer? (jtree-node->datum node))
        (label-icon-set! l icon1))))
Function: jtree-node->datum jtree-node

converts the Swing tree node to the object.

Function: jtree-node->datum-tree jtree-node

converts the Swing tree under the node to a list of the objects.

Function: jtree-node-insert! jtree jtree-node datum row

inserts the datum to the rowth of the Swing tree node.

Function: jtree-node-add! jtree jtree-node datum

adds the datum to the Swing tree node.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.36.24 Changing look and feels

Function: installed-look-and-feel-names

returns a list of installed look and feels.

Function: look-and-feel-set! look-and-feel-name

sets the look and feel to the given name.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.36.25 Swing timers

Function: make-swing-timer init-delay listener [delay]

creates a Swing timer.
init-delay specifies initial delay in milliseconds and delay in milliseconds if delay is not specified. delay specifies delay. If delay is #f, timer will start only once.
listener is a procedure with one argument and called by timer.

Function: swing-timer-start swing-timer

starts the Swing timer.

Function: swing-timer-stop swing-timer

stops the Swing timer.

Function: swing-timer-restart swing-timer

restarts the Swing timer.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.36.26 Threads

Function: swing-invoke-later thread

starts the thread later in the Swing dispatch thread.
To manipulate any GUI component, you should call this procedure because Swing framework is not support multithread perfectly.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.36.27 Events

Function: action-listener-add! component action-proc

adds the action listener action-proc to the component. action-proc must be a procedure with one argument.

Function: mouse-listener-add! component event-proc

adds the mouse listener event-proc to the component. event-proc must be a procedure with one argument.

Function: item-listener-add! component event-proc

adds the item listener event-proc to the component. event-proc must be a procedure with one argument.

Function: adjustment-listener-add! component event-proc

adds the adjustment listener event-proc to the component. event-proc must be a procedure with one argument.

Function: change-listener-add! component event-proc

adds the change listener event-proc to the component. event-proc must be a procedure with one argument.

Function: window-listener-add! component event-proc

adds the window listener event-proc to the component. event-proc must be a procedure with one argument.

Function: get-action-command action-event-object

gets the action command from the given event object.

Function: get-when action-event-object

gets the SRFI-19 time when the action is occurred from the given event object.

Function: get-param-string action-event-object

gets the parameter string from the given event object.

Function: get-mouse-button mouse-event-object

gets a symbol indicates the mouse button which is pressed from the given event object.
Symbols of mouse buttons are shown as follows.

symboldescription
no-buttonno button clicked
button1first button clicked(left button in the Windows or UNIX environment)
button2second button clicked(right button in the Windows environment)
button3third button clicked(right button in the UNIX environment)
unknown-buttonunknown button clicked
Function: get-mouse-click-count mouse-event-object

gets the times which a mouse button clicked.

Function: get-mouse-x mouse-event-object

gets the x-coordinate in which a mouse button clicked. Coordinate system is the component coordinate system.

Function: get-mouse-y mouse-event-object

gets the y-coordinate in which a mouse button clicked. Coordinate system is the component coordinate system.

Function: popup-trigger? mouse-event-object

returns #t if the event object is a popup trigger.

Function: get-event-selected-item-value item-event-object

gets selected items from the event object.

Function: get-event-adjustment-value adjustment-event-object

gets adjusted items from the event object.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.36.28 Others

Function: beep

rings a bell.

Function: update-component-tree-ui component

updates the component UI.


[ << ] [ < ] [ Up ] [ > ] [ >> ]

This document was generated on August 9, 2012 using texi2html 5.0.