javafx.scene.Scene.getWidth()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(248)

本文整理了Java中javafx.scene.Scene.getWidth()方法的一些代码示例,展示了Scene.getWidth()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Scene.getWidth()方法的具体详情如下:
包路径:javafx.scene.Scene
类名称:Scene
方法名:getWidth

Scene.getWidth介绍

暂无

代码示例

代码示例来源:origin: jfoenixadmin/JFoenix

private void updateWidth() {
  Window stage = getOwner();
  setWidth(stage.getScene().getWidth());
}

代码示例来源:origin: jfoenixadmin/JFoenix

@Override
  public void layoutChildren() {
    super.layoutChildren();
    if (dialog.getMinWidth() > 0 && dialog.getMinHeight() > 0) {
      return;
    }
    double minWidth = Math.max(0, computeMinWidth(getHeight()) + (dialog.getWidth() - customScene.getWidth()));
    double minHeight = Math.max(0, computeMinHeight(getWidth()) + (dialog.getHeight() - customScene.getHeight()));
    dialog.setMinWidth(minWidth);
    dialog.setMinHeight(minHeight);
  }
}

代码示例来源:origin: stackoverflow.com

private Stage stage;
private double decorationWidth;
private double decorationHeight;

public void start(Stage stage) throws Exception {
  this.stage = stage;

  final double initialSceneWidth = 720;
  final double initialSceneHeight = 640;
  final Parent root = createRoot();
  final Scene scene = new Scene(root, initialSceneWidth, initialSceneHeight);

  this.stage.setScene(scene);
  this.stage.show();

  this.decorationWidth = initialSceneWidth - scene.getWidth();
  this.decorationHeight = initialSceneHeight - scene.getHeight();
}

public void resizeScene(double width, double height) {
  this.stage.setWidth(width + this.decorationWidth);
  this.stage.setHeight(height + this.decorationHeight);
}

代码示例来源:origin: stackoverflow.com

Scene oldScene = menuBar.getScene();
Stage stage = (Stage) oldScene.getWindow();
Parent root;
try {
  root = FXMLLoader.load(getClass().getResource(window + ".fxml"));
Scene scene = new Scene(root, oldScene.getWidth(), oldScene.getHeight());
stage.setScene(scene);

代码示例来源:origin: org.jfxtras/jfxtras-common

/**
 * 
 * @return
 */
double determineActualDiagonalInInches() {
  Scene lScene = getScene();
  
  // determine the DPI factor, so the thresholds become larger on screens with a higher DPI
  double lPPI = determinePPI();
  double lWidthInInches = lScene.getWidth() / lPPI;
  double lHeightInInches = lScene.getHeight() / lPPI;
  double lDiagonalInInches = Math.sqrt( (lWidthInInches * lWidthInInches) + (lHeightInInches * lHeightInInches) );
  if (getTrace()) System.out.println("Actual scene size=" + lScene.getWidth() + "x" + lScene.getHeight() + "px, scene diagonal in inches=" + lDiagonalInInches + " (ppi=" + lPPI + ")");
  return lDiagonalInInches;
}

代码示例来源:origin: stackoverflow.com

sceneWidth = scene.getWidth(),
sceneHeight = scene.getHeight();

代码示例来源:origin: com.machinepublishers/jbrowserdriver

void mouseMoveBy(final double viewportX, final double viewportY) {
 lock();
 try {
  AppThread.exec(context.item().statusCode, () -> {
   Stage stage = context.item().stage.get();
   robot.get().mouseMove(
     (int) Math.rint(Math.max(0, Math.min(stage.getScene().getWidth() - 1,
       viewportX + new Double((Integer) robot.get().getMouseX())))),
     (int) Math.rint(Math.max(0, Math.min(stage.getScene().getHeight() - 1,
       viewportY + new Double((Integer) robot.get().getMouseY())))));
   return null;
  });
 } finally {
  unlock();
 }
}

代码示例来源:origin: stackoverflow.com

@Override
public void start(Stage primaryStage) {
  StackPane root = new StackPane();
  Scene scene = new Scene(root, 800, 600);
  primaryStage.setScene(scene);

  System.out.println("before sceneW " + scene.getWidth());
  System.out.println("before sceneH " +  scene.getHeight());
  System.out.println("before stageW " + primaryStage.getWidth());
  System.out.println("before stageH " + primaryStage.getHeight());

  primaryStage.show();

  System.out.println("after sceneW " + scene.getWidth());
  System.out.println("after sceneH " +  scene.getHeight());
  System.out.println("after stageW " + primaryStage.getWidth());
  System.out.println("after stageH " + primaryStage.getHeight());

  primaryStage.setMinWidth(primaryStage.getWidth());
  primaryStage.setMinHeight(primaryStage.getHeight());
}

代码示例来源:origin: com.jfoenix/jfoenix

private void updateWidth() {
  Window stage = getOwner();
  setWidth(stage.getScene().getWidth());
}

代码示例来源:origin: com.nexitia.emaginplatform/emagin-jfxcore-engine

public static double mainSceneWidth() {
 if (instance().getScene() == null) {
  return 900L;
 }
 return instance().getScene().getWidth();
}

代码示例来源:origin: stackoverflow.com

titleContent.setOnMouseDragged(new EventHandler<MouseEvent>() {
  public void handle(MouseEvent mouseEvent) {
      Scene scene = (Scene) titleContent.getScene();
      if (!(mouseEvent.getX() < border || mouseEvent.getX() > scene.getWidth() -border) && !(mouseEvent.getX() < border && mouseEvent.getY() > scene.getHeight() -border)){
        Stage stage = (Stage) titleContent.getScene().getWindow();
        Screen screen = Screen.getPrimary();
        Rectangle2D bounds = screen.getVisualBounds();

        if (stage.getWidth()==bounds.getMaxX() && stage.getHeight()==bounds.getMaxY()){
          stage.setWidth(minWidth);
          stage.setHeight(minHeight);
        }

        stage.setX(mouseEvent.getScreenX() + dragDelta.x);
        stage.setY(mouseEvent.getScreenY() + dragDelta.y);
      }

}

代码示例来源:origin: org.loadui/testFx

public static boolean isNodeWithinSceneBounds(Node node)
{
  Scene scene = node.getScene();
  Bounds nodeBounds = node.localToScene( node.getBoundsInLocal() );
  return nodeBounds.intersects( 0, 0, scene.getWidth(), scene.getHeight() );
}

代码示例来源:origin: org.refcodes/refcodes-checkerboard-alt-javafx

/**
 * Inits the min stage width.
 */
private void initMinStageWidth() {
  if ( _stage != null && _scene != null ) {
    if ( Double.isNaN( _bordersH ) ) {
      initBordersH( _scene.getWidth() );
    }
    else {
      int theWidth = (int) _bordersH;
      theWidth += (getViewportWidth() * getFieldWidth() + getViewportWidth() * getFieldGap());
      _stage.setMinWidth( theWidth + _windowDecorationH );
    }
  }
}

代码示例来源:origin: com.machinepublishers/jbrowserdriver

void mouseMove(final double viewportX, final double viewportY) {
 lock();
 try {
  AppThread.exec(context.item().statusCode, () -> {
   Stage stage = context.item().stage.get();
   double adjustedX = Math.max(0, Math.min(viewportX, stage.getScene().getWidth() - 1));
   double adjustedY = Math.max(0, Math.min(viewportY, stage.getScene().getHeight() - 1));
   robot.get().mouseMove(
     (int) Math.rint(adjustedX
       + (Double) stage.getX()
       + (Double) stage.getScene().getX()),
     (int) Math.rint(adjustedY
       + (Double) stage.getY()
       + (Double) stage.getScene().getY()));
   return null;
  });
 } finally {
  unlock();
 }
}

代码示例来源:origin: com.jfoenix/jfoenix

@Override
  public void layoutChildren() {
    super.layoutChildren();
    if (dialog.getMinWidth() > 0 && dialog.getMinHeight() > 0) {
      return;
    }
    double minWidth = Math.max(0, computeMinWidth(getHeight()) + (dialog.getWidth() - customScene.getWidth()));
    double minHeight = Math.max(0, computeMinHeight(getWidth()) + (dialog.getHeight() - customScene.getHeight()));
    dialog.setMinWidth(minWidth);
    dialog.setMinHeight(minHeight);
  }
}

代码示例来源:origin: stackoverflow.com

primaryStage.show();
opaqueLayer.resizeRelocate(0, 0, scene.getWidth(), scene.getHeight());

代码示例来源:origin: org.processing/core

public void setSize(int wide, int high) {
 // When the surface is set to resizable via surface.setResizable(true),
 // a crash may occur if the user sets the window to size zero.
 // https://github.com/processing/processing/issues/5052
 if (high <= 0) {
  high = 1;
 }
 if (wide <= 0) {
  wide = 1;
 }
 //System.out.format("%s.setSize(%d, %d)%n", getClass().getSimpleName(), width, height);
 Scene scene = stage.getScene();
 double decorH = stage.getWidth() - scene.getWidth();
 double decorV = stage.getHeight() - scene.getHeight();
 stage.setWidth(wide + decorH);
 stage.setHeight(high + decorV);
 fx.setSize(wide, high);
}

代码示例来源:origin: sc.fiji/OMEVisual

public void initFX(JFXPanel fxPanel) {
  // Init the root layout
  try {
    FXMLLoader loader = new FXMLLoader();
    loader.setLocation(MainAppFrame.class.getResource("/sc/fiji/omevisual/gui/view/RootLayout.fxml"));
    AnchorPane rootLayout = (AnchorPane) loader.load();
    // Get the controller and add an ImageJ context to it.
    RootLayoutController controller = loader.getController();
    controller.setContext(ij.context());
    controller.setImage(this.image);
    // Show the scene containing the root layout.
    Scene scene = new Scene(rootLayout);
    this.fxPanel.setScene(scene);
    // Resize the JFrame to the JavaFX scene
    this.setSize((int) scene.getWidth(), (int) scene.getHeight());
    controller.fill(md);
  } catch (IOException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: com.aquafx-project/aquafx

public Node getContent(Scene scene) {
  // TabPane
  final TabPane tabPane = new TabPane();
  tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE);
  tabPane.setPrefWidth(scene.getWidth());
  tabPane.setPrefHeight(scene.getHeight());
  tabPane.prefWidthProperty().bind(scene.widthProperty());
  tabPane.prefHeightProperty().bind(scene.heightProperty());
  // list view examples
  Tab listViewTab = new Tab("ListView");
  buildListViewTab(listViewTab);
  tabPane.getTabs().add(listViewTab);
  // tree view examples
  Tab treeViewTab = new Tab("TreeView");
  buildTreeViewTab(treeViewTab);
  tabPane.getTabs().add(treeViewTab);
  // table view examples
  Tab tableViewTab = new Tab("TableView");
  buildTableViewTab(tableViewTab);
  tabPane.getTabs().add(tableViewTab);
  return tabPane;
}

代码示例来源:origin: com.bitplan.radolan/com.bitplan.radolan

/**
 * show the sizes of stage, scene, and the given other nodes
 * 
 * @param region
 *          - the regions to show
 */
public void showSizes(Region... regions) {
 System.out.println("Sizes: ");
 ObservableList<Screen> screens = Screen.getScreensForRectangle(stage.getX(),
   stage.getY(), stage.getWidth(), stage.getHeight());
 for (Screen screen : screens) {
  Rectangle2D s = screen.getVisualBounds();
  showSize(screen, s.getWidth(), s.getHeight());
 }
 showSize(stage, stage.getWidth(), stage.getHeight());
 showSize(getScene(), getScene().getWidth(), getScene().getHeight());
 ImageView imageView = mapView.getImageView();
 showSize(imageView, imageView.getFitWidth(), imageView.getFitHeight());
 Image image = mapView.getImage();
 showSize(image, image.getWidth(), image.getHeight());
 for (Region region : regions) {
  showSize(region, region.getWidth(), region.getHeight());
 }
}

相关文章