O1Library Docs
Fall 2026
Docs API

# Dialog

o1.gui.Dialog
object Dialog

This object provides convenience methods for displaying messages and reading user input via simple Swing dialogs.

## Attributes

Graph
Supertypes
  class Object
  trait Matchable
  class Any
Self type
  Dialog.type

## Members list

### Type members

#### Classlikes

case object Centered extends Position

A positioning policy that centers the dialog onscreen. An alternative to RelativeTo.

A positioning policy that centers the dialog onscreen. An alternative to RelativeTo.

## Attributes

Supertypes
  trait Singleton
  trait Product
  trait Mirror
  trait Serializable
  trait Product
  trait Equals
  trait Position
  class Object
  trait Matchable
  class Any
  Show all
Self type
  Centered.type

sealed trait Position

The positioning policy of an input dialog. Used with the methods on Dialog.

The positioning policy of an input dialog. Used with the methods on Dialog.

## Attributes

See also

  RelativeTo, Centered

Supertypes
  class Object
  trait Matchable
  class Any
Known subtypes
  object Centered
  class RelativeTo

final case class RelativeTo(locator: Component) extends Position

A positioning policy that places the dialog near another Swing component. An alternative to Centered.

A positioning policy that places the dialog near another Swing component. An alternative to Centered.

## Parameters

locator

  the Swing component in front of which the dialog should appear

## Attributes

Companion
  object
Supertypes
  trait Serializable
  trait Product
  trait Equals
  trait Position
  class Object
  trait Matchable
  class Any
  Show all

case object RelativeTo

A companion object with factory methods.

A companion object with factory methods.

## Attributes

Companion
  class
Supertypes
  trait Singleton
  trait Product
  trait Mirror
  trait Serializable
  trait Product
  trait Equals
  class Object
  trait Matchable
  class Any
  Show all
Self type
  RelativeTo.type

### Value members

#### Concrete methods

def display(message: String)(using position: Position): Unit

Displays a textual message in a Swing dialog.

Displays a textual message in a Swing dialog.

## Parameters

message

  a message to the end user

position

  the location of the dialog onscreen

## Attributes

def requestAnyDouble(prompt: String)(using position: Position): Option[Double]

Asks the user to input a decimal number by typing it in a Swing dialog. Keeps prompting the user with new dialogs until it receives text interpretable as a `Double` or the user cancels.

Asks the user to input a decimal number by typing it in a Swing dialog. Keeps prompting the user with new dialogs until it receives text interpretable as a `Double` or the user cancels.

## Parameters

position

  the location of the dialog(s) onscreen

prompt

  a message that prompts the user for input

## Attributes

Returns

  the user input, converted from the textual input with `toDouble`; `None` if the user canceled

def requestAnyInt(prompt: String, errorMessage: String)(using position: Position): Option[Int]

Asks the user to input an integer by typing it in a Swing dialog. Keeps prompting the user with new dialogs until it receives text interpretable as a `Double` or the user cancels.

Asks the user to input an integer by typing it in a Swing dialog. Keeps prompting the user with new dialogs until it receives text interpretable as a `Double` or the user cancels.

## Parameters

errorMessage

  a prefix added to `prompt` on each request except the first

position

  the location of the dialog(s) onscreen

prompt

  a message that prompts the user for input

## Attributes

Returns

  the user input, converted from the textual input with `toInt`; `None` if the user canceled

def requestAnyLine(prompt: String)(using position: Position): Option[String]

Asks the user to input a line of text via a Swing dialog; accepts any string as input.

Asks the user to input a line of text via a Swing dialog; accepts any string as input.

## Parameters

position

  the location of the dialog onscreen

prompt

  a message that prompts the user for input

## Attributes

Returns

  the string entered by the user; `None` if they canceled

def requestChoice[Choice](prompt: String, options: Seq[Choice])(using position: Position): Option[Choice]

Asks the user to choose among the given options via a Swing dialog.

Asks the user to choose among the given options via a Swing dialog.

## Parameters

options

  any objects that the user will choose one of; their `toString`s will show in the input dialog

position

  the location of the dialog onscreen

prompt

  a message that prompts the user for input

## Attributes

Returns

  one of the `options` as chosen by the user; `None` if the user canceled

def requestDouble(prompt: String, isOK: Double => Boolean, errorMessage: String)(using position: Position): Option[Double]

Asks the user to input a decimal number by typing it in a Swing dialog. Keeps prompting the user with new dialogs until it receives a valid input or the user cancels. An input is invalid if `isOK(inputString.toDouble)` returns `false` or fails with an exception.

Asks the user to input a decimal number by typing it in a Swing dialog. Keeps prompting the user with new dialogs until it receives a valid input or the user cancels. An input is invalid if `isOK(inputString.toDouble)` returns `false` or fails with an exception.

## Parameters

errorMessage

  a prefix added to `prompt` on each request except the first

isOK

  a function applied to any actual `Double` input to check if it’s valid

position

  the location of the dialog(s) onscreen

prompt

  a message that prompts the user for input

## Attributes

Returns

  the user input, converted from the textual input with `toDouble`; `None` if the user canceled

def requestInput[Input](prompt: String, convert: String => Input, isOK: Input => Boolean, errorMessage: String)(using position: Position): Option[Input]

Asks the user to input a line of text via a Swing dialog and interprets the input with the given functions. Keeps prompting the user with new dialogs until it receives a valid input or the user cancels. An input is invalid if `isOK(convert(input))` returns `false` or fails with an exception.

Asks the user to input a line of text via a Swing dialog and interprets the input with the given functions. Keeps prompting the user with new dialogs until it receives a valid input or the user cancels. An input is invalid if `isOK(convert(input))` returns `false` or fails with an exception.

## Type parameters

Input

  the type of the user input (converted from a string to this type)

## Parameters

convert

  a function applied to the input string to produce the actual return value

errorMessage

  a prefix added to `prompt` on each request except the first

isOK

  a function applied to the input string to check if it’s valid

position

  the location of the dialog(s) onscreen

prompt

  a message that prompts the user for input

## Attributes

Returns

  a valid user input (converted from a string); `None` if the user canceled

def requestInt(prompt: String, isOK: Int => Boolean, errorMessage: String)(using position: Position): Option[Int]

Asks the user to input an integer by typing it in a Swing dialog. Keeps prompting the user with new dialogs until it receives a valid input or the user cancels. An input is invalid if `isOK(inputString.toInt)` returns `false` or fails with an exception.

Asks the user to input an integer by typing it in a Swing dialog. Keeps prompting the user with new dialogs until it receives a valid input or the user cancels. An input is invalid if `isOK(inputString.toInt)` returns `false` or fails with an exception.

## Parameters

errorMessage

  a prefix added to `prompt` on each request except the first

isOK

  a function applied to any actual integer input to check if it’s valid

position

  the location of the dialog(s) onscreen

prompt

  a message that prompts the user for input

## Attributes

Returns

  the user input, converted from the textual input with `toInt`; `None` if the user canceled

def requestNonEmptyLine(prompt: String, errorMessage: String)(using position: Position): Option[String]

Asks the user to input a non-empty line of text via a Swing dialog. Keeps prompting the user with new dialogs until it receives a non-empty string as input or the user cancels.

Asks the user to input a non-empty line of text via a Swing dialog. Keeps prompting the user with new dialogs until it receives a non-empty string as input or the user cancels.

## Parameters

errorMessage

  a prefix added to `prompt` on each request except the first

position

  the location of the dialog(s) onscreen

prompt

  a message that prompts the user for input

## Attributes

Returns

  the user input, a non-empty string; `None` if the user canceled

def requestString(prompt: String, isOK: String => Boolean, errorMessage: String)(using position: Position): Option[String]

Asks the user to input a line of text via a Swing dialog. Keeps prompting the user with new dialogs until it receives a valid input or the user cancels. An input is invalid if `isOK(input.trim)` returns `false` or fails with an exception.

Asks the user to input a line of text via a Swing dialog. Keeps prompting the user with new dialogs until it receives a valid input or the user cancels. An input is invalid if `isOK(input.trim)` returns `false` or fails with an exception.

## Parameters

errorMessage

  a prefix added to `prompt` on each request except the first

isOK

  a function applied to the input string to check if it’s valid

position

  the location of the dialog(s) onscreen

prompt

  a message that prompts the user for input

## Attributes

Returns

  a valid user input, trimmed for whitespce; `None` if the user canceled