标签: javafx-8

如何在使用鼠标拖动调整选项卡窗格时调整组件大小

我已经实现了位于中心的选项卡窗格的非常简单的鼠标拖动.鼠标调整大小是非常基本的,它不能很好地工作但是现在我可以拖动选项卡的边框并增加大小.

在此输入图像描述

现在我发现了一个问题.当我调整位于中心的标签大小时,位于中心旁边的组件不会按照用户的预期自动推回和尖叫,它们会放在我调整大小的组件后面.当我用鼠标拖动扩展主要组件时,我可以以某种方式设置所有组件被推回吗?

javafx javafx-2 javafx-8

1
推荐指数
1
解决办法
4882
查看次数

如何在JavaFX中围绕自定义枢轴旋转对象?

我想围绕一个自定义枢轴旋转一个对象,这是它的重点,所以我有这样的代码:

private final EventHandler<MouseEvent> mouseEventHandler = new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent mouseEvent) {
            if (mouseEvent.getEventType() == MouseEvent.MOUSE_PRESSED) {
                dragStartX = mouseEvent.getSceneX();
                dragStartY = mouseEvent.getSceneY();
                mousePosX = mouseEvent.getSceneX();
                mousePosY = mouseEvent.getSceneY();
                mouseOldX = mouseEvent.getSceneX();
                mouseOldY = mouseEvent.getSceneY();

                if (mouseEvent.isMiddleButtonDown()) {
                    pivot = mouseEvent.getPickResult().getIntersectedPoint();
                    camForm1.rx.setPivotX(pivot.getX());
                    camForm1.ry.setPivotY(pivot.getY());
                    camForm1.rz.setPivotZ(pivot.getZ());
                    System.out.println(pivot);
                }

            } else if (mouseEvent.getEventType() == MouseEvent.MOUSE_DRAGGED) {

                double modifier = 1.0;
                double modifierFactor = 0.3;

                if (mouseEvent.isControlDown()) {
                    modifier = 0.1;
                }
                if (mouseEvent.isShiftDown()) {
                    modifier = 10.0;
                }

                mouseOldX = …
Run Code Online (Sandbox Code Playgroud)

3d javafx-8

1
推荐指数
1
解决办法
9941
查看次数

Java Fx TreeTableView不同的上下文菜单项

我正在使用TreeTableView,并且我想根据所选行内的数据更改与上下文菜单关联的菜单项。

假设我有一个结构如下的表:


访客


访客1

访客2

访客3

不休


ter不休1

chatter2


在此表中,我们可以比喻说我们有两个根节点,分别是“访问者”和“ Chatters”。现在,我想有两个带有不同选项的上下文菜单。可以说,针对访问者的上下文菜单有一个项目是“邀请聊天”,另一个上下文菜单处理聊天者,并且具有不同的选项,例如:“踢”,“禁止”等。我的问题是如何实现这种情况?我应该在哪里使用这些上下文菜单?我应该将它们用于单元格,行还是表格?

java contextmenu java-8 javafx-8 treetableview

1
推荐指数
1
解决办法
1634
查看次数

JavaFX SortedList:监听列表更改和列表项更新事件

使用案例:

  • 有序的ListView(或TableView)
  • 插入后显示
  • 在显示之后进行键的更新

启动时列表:

在启动时列出

添加18后:

加18后

更新后:

更新后

你可以看到没有任何变化!

代码:

public final class SortedListTest extends Application {

   @Override
   public void start( Stage stage ) throws Exception {
      final ObservableList<IntegerProperty> il =
         FXCollections.observableArrayList();
      il.add( new SimpleIntegerProperty( 12 ));
      il.add( new SimpleIntegerProperty( 24 ));
      il.add( new SimpleIntegerProperty( 36 ));
      final Button add    = new Button( "Add 18" );
      final Button update = new Button( "Update 24 to 8" );
      final HBox   ctrl   = new HBox( 4.0, add, update );
      final ListView<IntegerProperty> listVw = …
Run Code Online (Sandbox Code Playgroud)

java sorting javafx-8

1
推荐指数
1
解决办法
3423
查看次数

为ScrollPane的子级添加边距

我创建了这个简单的例子来向您展示我遇到的问题:

import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class MainApp extends Application
{

    private final StackPane stackPane = new StackPane();

    @Override
    public void start(Stage stage) throws Exception
    {

        ScrollPane scroll = new ScrollPane();

        stackPane.getChildren().addAll(scroll, comboPane());
        stackPane.setStyle("-fx-background-color: white;");

        stackPane.setAlignment(Pos.TOP_RIGHT);
        stackPane.setPrefSize(900, 900);

        FlowPane flowPane;

        flowPane = new FlowPane(Orientation.HORIZONTAL);
        flowPane.setVgap(10);
        flowPane.setHgap(10);

        flowPane.setPadding(new Insets(15, 15, 15, 15));
        flowPane.setStyle("-fx-background-color: white;"); …
Run Code Online (Sandbox Code Playgroud)

javafx javafx-8

1
推荐指数
1
解决办法
1368
查看次数

从ListView拖放到TreeView

我只是想将一个项目从我的拖放到我ListView的特定位置TreeView.我知道如何处理DragEvents.但是如何才能获得treeView的删除位置?"position"我的意思是"在哪个treeview-item上放下(从这个treeview-item获取引用)".

package main;

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.event.EventType;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.DragEvent;
import javafx.scene.input.MouseDragEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import javafx.util.Callback;



public class Program extends Application {
    String buffer = "";

    public static void main(String args[]) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        primaryStage.setTitle("Tree View Sample");
        HBox box = new …
Run Code Online (Sandbox Code Playgroud)

java drag-and-drop javafx javafx-8

1
推荐指数
1
解决办法
2007
查看次数

如果TabPane没有选项卡,则显示标签

我想在中心显示标签是空的:

private TabPane tabPane = new TabPane();
private Text placeHolder = new Text("Empty");
placeHolder.setFont(Font.font(null, FontWeight.BOLD, 20));
placeHolder.visibleProperty().bind(Bindings.isEmpty(tabPane.getChildren()));
Run Code Online (Sandbox Code Playgroud)

实现这个的正确方法是什么?

javafx javafx-8

1
推荐指数
1
解决办法
631
查看次数

JavaFX加载FXML的性能问题

我有一个主文件有切换按钮,单击其中一个按钮我启动一个新的FXMLLoader,有大约10个SVG,15个Textfield和6个微调器.此外,它有CSS来相应地渲染节点...它加载正常,没有错误或任何问题,但在显示场景之前需要一两秒钟.

我想这是由于节点数量同时被初始化.有没有办法在节点开始初始化之前显示场景?

注意:我的项目要求我在点击时导航到不同的场景.

从中选择ToggleButton

   if(settings.isSelected()){
        Stage stage = (Stage) mainWrapper.getScene().getWindow();
        Parent root = FXMLLoader.load(getClass().getResource("/fxmlFiles/settings.fxml"));
        stage.setScene(new Scene(root, Screen.getPrimary().getVisualBounds().getWidth(),
                Screen.getPrimary().getVisualBounds().getHeight()));
        stage.centerOnScreen();
        //stage.setMaximized(true);
        stage.show();
    }
Run Code Online (Sandbox Code Playgroud)

fxmlFile

    <FlowPane xmlns:fx="http://javafx.com/fxml"
    fx:controller="controllers.motelInfoController"
    stylesheets="/cssFiles/motelInfo.css"
    fx:id="content">

    <VBox fx:id="mainWrapper">
    <VBox fx:id="validationWrapper">
        <Label fx:id="validationLabel" visible="false"/>
    </VBox>
    <VBox fx:id="generalInfo">
    <HBox> <!--First Row-->
            <HBox>
            <Group>
                <SVGPath fx:id="iconMotelName" scaleX="0.05" scaleY="0.05" fill="white"/>
            </Group>
            <Group>
                <TextField fx:id="miName" promptText="Motel Name"/>
            </Group>
            </HBox>
            <HBox>
                <Group>
                    <TextField fx:id="miFranchiseName" promptText="Franchise Name"/>
                </Group>
            </HBox>
        </HBox>
    <HBox> <!--Second Row-->
            <HBox>
                <Group>
                    <SVGPath fx:id="iconMotelAddress" scaleX="0.05" scaleY="0.05" fill="white"/>
                </Group>
                <Group>
                    <TextField …
Run Code Online (Sandbox Code Playgroud)

fxml javafx-8

1
推荐指数
1
解决办法
539
查看次数

在ImageView中缩放图像(javafx)

我正在尝试使用滑块缩放ImageView中的选定图像。我唯一能做的就是调整其中包含图像的整个ImageView的大小。但这不是我要寻找的。我只想使用具有相同大小的ImageView缩放图像。它应该是焦距的演示。我也在使用场景构建器。我只是所有这些的初学者,因此,非常感谢您的帮助。这就是我所拥有的。

public void openImage(ActionEvent event) {

    FileChooser fc = new FileChooser();
    File f = fc.showOpenDialog(null);
    if (f != null) {
        System.out.println(f.toURI().toString());
        Obrazok = new Image(f.toURI().toString());          
        imageView.setImage(Obrazok);
        imageView.setSmooth(true);
        imageView.setCache(true); 

    }
}
public void setOnZoom (MouseEvent e){

    imageView.scaleXProperty().bind(slider.valueProperty());
    imageView.scaleYProperty().bind(slider.valueProperty());
    Rectangle2D viewpoint = new Rectangle2D(0, 0, Obrazok.getRequestedHeight(), Obrazok.getRequestedWidth());
    imageView.setViewport(viewpoint);
    imageView.setViewport(viewpoint);
    imageView.setImage(Obrazok);
}
Run Code Online (Sandbox Code Playgroud)

javafx javafx-2 scenebuilder javafx-8

1
推荐指数
1
解决办法
3406
查看次数

JavaFX - 从TabPane中删除Tab不会触发setOnClosed()回调

我想在setOnClosedJavaFX Tab 的回调中执行代码.但是,当我从TabPane中删除Tab时:

TabPane rootTabPane;
rootTabPane.getTabs().remove(tab1);
Run Code Online (Sandbox Code Playgroud)

在选项卡的控制器中,永远不会执行回调:

tab1.setOnClosed(event -> timerStop());
Run Code Online (Sandbox Code Playgroud)

通过鼠标单击关闭选项卡时,将运行回调,但不会在代码中删除选项卡时运行回调.

如何关闭代码中的选项卡以便调用回调?我有许多选项卡具有非常不同的行为,并希望使用通用方法.

谢谢!

javafx javafx-8

1
推荐指数
1
解决办法
87
查看次数