Что такое stage java

Class Stage

The JavaFX Stage class is the top level JavaFX container. The primary Stage is constructed by the platform. Additional Stage objects may be constructed by the application.

Stage objects must be constructed and modified on the JavaFX Application Thread.

The JavaFX Application Thread is created as part of the startup process for the JavaFX runtime. See the Application class and the Platform.startup(Runnable) method for more information.

Many of the Stage properties are read only because they can be changed externally by the underlying platform and therefore must not be bindable.

  • StageStyle.DECORATED — a stage with a solid white background and platform decorations.
  • StageStyle.UNDECORATED — a stage with a solid white background and no decorations.
  • StageStyle.TRANSPARENT — a stage with a transparent background and no decorations.
  • StageStyle.UTILITY — a stage with a solid white background and minimal platform decorations.

The style must be initialized before the stage is made visible.

On some platforms decorations might not be available. For example, on some mobile or embedded devices. In these cases a request for a DECORATED or UTILITY window will be accepted, but no decorations will be shown.

A stage can optionally have an owner Window. When a window is a stage’s owner, it is said to be the parent of that stage.

Читайте также:  Php switch case синтаксис

Owned Stages are tied to the parent Window. An owned stage will always be on top of its parent window. When a parent window is closed or iconified, then all owned windows will be affected as well. Owned Stages cannot be independantly iconified.

The owner must be initialized before the stage is made visible.

  • Modality.NONE — a stage that does not block any other window.
  • Modality.WINDOW_MODAL — a stage that blocks input events from being delivered to all windows from its owner (parent) to its root. Its root is the closest ancestor window without an owner.
  • Modality.APPLICATION_MODAL — a stage that blocks input events from being delivered to all windows from the same application, except for those from its child hierarchy.

When a window is blocked by a modal stage its Z-order relative to its ancestors is preserved, and it receives no input events and no window activation events, but continues to animate and render normally. Note that showing a modal stage does not necessarily block the caller. The show() method returns immediately regardless of the modality of the stage. Use the showAndWait() method if you need to block the caller until the modal stage is hidden (closed). The modality must be initialized before the stage is made visible.

 import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.text.Font; import javafx.scene.text.Text; import javafx.stage.Stage; public class HelloWorld extends Application < @Override public void start(Stage stage) < Text text = new Text(10, 40, "Hello World!"); text.setFont(new Font(40)); Scene scene = new Scene(new Group(text)); stage.setTitle("Welcome to JavaFX!"); stage.setScene(scene); stage.sizeToScene(); stage.show(); >public static void main(String[] args) < Application.launch(args); >> 

produces the following on Windows:

A visual rendering of a JavaFX Stage on Windows

produces the following on Mac OSX:

A visual rendering of a JavaFX Stage on Mac OSX

produces the following on Linux:

A visual rendering of a JavaFX Stage on Linux

Property Summary

Properties inherited from class javafx.stage.Window

Constructor Summary

Method Summary

Specifies the text to show when a user enters full screen mode, usually used to indicate the way a user should go about exiting out of full screen mode.

Methods inherited from class javafx.stage.Window

Methods inherited from class java.lang.Object

Property Details

fullScreen

  • Applications can only enter full-screen mode in response to user input. More specifically, entering is allowed from mouse ( Node.mousePressed/mouseReleased/mouseClicked ) or keyboard ( Node.keyPressed/keyReleased/keyTyped ) event handlers. It is not allowed to enter full-screen mode in response to ESC key. Attempting to enter full-screen mode from any other context will be ignored. If Stage was constructed as full-screen but not visible it will enter full-screen mode upon becoming visible, with the same limitations to when this is allowed to happen as when setting fullScreen to true .
  • If the application was allowed to enter full-screen mode it will have limited keyboard input. It will only receive KEY_PRESSED and KEY_RELEASED events from the following keys: UP, DOWN, LEFT, RIGHT, SPACE, TAB, PAGE_UP, PAGE_DOWN, HOME, END, ENTER

title

iconified

Defines whether the Stage is iconified or not. In case that more Stage modes are set simultaneously their order of importance is iconified> fullScreen , maximized (from strongest to weakest). On some mobile and embedded platforms setting this property to true will hide the Stage but not show an icon for it. The property is read only because it can be changed externally by the underlying platform and therefore must not be bindable.

maximized

Defines whether the Stage is maximized or not. In case that more Stage modes are set simultaneously their order of importance is iconified , fullScreen , maximized (from strongest to weakest). The property is read only because it can be changed externally by the underlying platform and therefore must not be bindable.

alwaysOnTop

Defines whether this Stage is kept on top of other windows. If some other window is already always-on-top then the relative order between these windows is unspecified (depends on platform). If a security manager is present, the application must have the FXPermission «setWindowAlwaysOnTop» in order for this property to have any effect. If the application does not have permission, attempting to set this property will be ignored and the property value will be restored to false . The property is read only because it can be changed externally by the underlying platform and therefore must not be bindable.

resizable

Defines whether the Stage is resizable or not by the user. Programatically you may still change the size of the Stage. This is a hint which allows the implementation to optionally make the Stage resizable by the user. Warning: Since 8.0 the property cannot be bound and will throw RuntimeException on an attempt to do so. This is because the setting of resizable is asynchronous on some systems or generally might be set by the system / window manager.
Bidirectional binds are still allowed, as they don’t block setting of the property by the system.

minWidth

minHeight

maxWidth

maxHeight

fullScreenExitKey

fullScreenExitHint

Constructor Details

Stage

Stage

Method Details

setScene

show

showAndWait

  • the application calls the Window.hide() or close() method on this stage
  • this stage has a non-null owner window, and its owner is closed
  • the user closes the window via the window system (for example, by pressing the close button in the window decoration)

After the Stage is hidden, and the application has returned from the event handler to the event loop, the nested event loop terminates and this method returns to the caller.

For example, consider the following sequence of operations for different event handlers, assumed to execute in the order shown below:

void evtHander1(. ) < stage1.showAndWait(); doSomethingAfterStage1Closed(. ) >void evtHander2(. )

evtHandler1 will block at the call to showAndWait. It will resume execution after stage1 is hidden and the current event handler, in this case evtHandler2, returns to the event loop. This means that doSomethingElseHere will execute before doSomethingAfterStage1Closed.

More than one stage may be shown with showAndWait. Each call will start a new nested event loop. The stages may be hidden in any order, but a particular nested event loop (and thus the showAndWait method for the associated stage) will only terminate after all inner event loops have also terminated.

For example, consider the following sequence of operations for different event handlers, assumed to execute in the order shown below:

void evtHander1() < stage1.showAndWait(); doSomethingAfterStage1Closed(. ) >void evtHander2() < stage2.showAndWait(); doSomethingAfterStage2Closed(. ) >void evtHander3() < stage1.hide(); doSomethingElseHere(. ) >void evtHander4()

evtHandler1 will block at the call to stage1.showAndWait, starting up a nested event loop just like in the previous example. evtHandler2 will then block at the call to stage2.showAndWait, starting up another (inner) nested event loop. The first call to stage1.showAndWait will resume execution after stage1 is hidden, but only after the inner nested event loop started by stage2.showAndWait has terminated. This means that the call to stage1.showAndWait won’t return until after evtHandler2 has returned. The order of execution is: stage1.showAndWait, stage2.showAndWait, stage1.hide, doSomethingElseHere, stage2.hide, doSomethingElseHereToo, doSomethingAfterStage2Closed, doSomethingAfterStage1Closed.

This method must not be called on the primary stage or on a stage that is already visible. Additionally, it must either be called from an input event handler or from the run method of a Runnable passed to Platform.runLater . It must not be called during animation or layout processing.

initStyle

Specifies the style for this stage. This must be done prior to making the stage visible. The style is one of: StageStyle.DECORATED, StageStyle.UNDECORATED, StageStyle.TRANSPARENT, or StageStyle.UTILITY.

getStyle

initModality

Specifies the modality for this stage. This must be done prior to making the stage visible. The modality is one of: Modality.NONE, Modality.WINDOW_MODAL, or Modality.APPLICATION_MODAL.

getModality

initOwner

Specifies the owner Window for this stage, or null for a top-level, unowned stage. This must be done prior to making the stage visible.

getOwner

setFullScreen

  • Applications can only enter full-screen mode in response to user input. More specifically, entering is allowed from mouse ( Node.mousePressed/mouseReleased/mouseClicked ) or keyboard ( Node.keyPressed/keyReleased/keyTyped ) event handlers. It is not allowed to enter full-screen mode in response to ESC key. Attempting to enter full-screen mode from any other context will be ignored. If Stage was constructed as full-screen but not visible it will enter full-screen mode upon becoming visible, with the same limitations to when this is allowed to happen as when setting fullScreen to true .
  • If the application was allowed to enter full-screen mode it will have limited keyboard input. It will only receive KEY_PRESSED and KEY_RELEASED events from the following keys: UP, DOWN, LEFT, RIGHT, SPACE, TAB, PAGE_UP, PAGE_DOWN, HOME, END, ENTER

isFullScreen

  • Applications can only enter full-screen mode in response to user input. More specifically, entering is allowed from mouse ( Node.mousePressed/mouseReleased/mouseClicked ) or keyboard ( Node.keyPressed/keyReleased/keyTyped ) event handlers. It is not allowed to enter full-screen mode in response to ESC key. Attempting to enter full-screen mode from any other context will be ignored. If Stage was constructed as full-screen but not visible it will enter full-screen mode upon becoming visible, with the same limitations to when this is allowed to happen as when setting fullScreen to true .
  • If the application was allowed to enter full-screen mode it will have limited keyboard input. It will only receive KEY_PRESSED and KEY_RELEASED events from the following keys: UP, DOWN, LEFT, RIGHT, SPACE, TAB, PAGE_UP, PAGE_DOWN, HOME, END, ENTER

fullScreenProperty

  • Applications can only enter full-screen mode in response to user input. More specifically, entering is allowed from mouse ( Node.mousePressed/mouseReleased/mouseClicked ) or keyboard ( Node.keyPressed/keyReleased/keyTyped ) event handlers. It is not allowed to enter full-screen mode in response to ESC key. Attempting to enter full-screen mode from any other context will be ignored. If Stage was constructed as full-screen but not visible it will enter full-screen mode upon becoming visible, with the same limitations to when this is allowed to happen as when setting fullScreen to true .
  • If the application was allowed to enter full-screen mode it will have limited keyboard input. It will only receive KEY_PRESSED and KEY_RELEASED events from the following keys: UP, DOWN, LEFT, RIGHT, SPACE, TAB, PAGE_UP, PAGE_DOWN, HOME, END, ENTER

getIcons

Gets the icon images to be used in the window decorations and when minimized. The images should be different sizes of the same image and the best size will be chosen, eg. 16×16, 32,32.

Источник

Оцените статью