【问题标题】:All my JavaFX TextFields have lines in them我所有的 JavaFX TextFields 中都有行
【发布时间】:2015-08-22 06:42:03
【问题描述】:

所以,在 JavaFX 上咬牙切齿,到目前为止一切进展顺利。

但是,所有文本字段都有一条横穿它们的线,距离顶部 10 像素左右。

不仅在我的应用程序中,在 SceneBuilder 应用程序中也是如此。

注意,我没有使用任何明确的 CSS,我不知道 SceneBuilder 使用什么。屏幕截图来自 SceneBuilder,我的屏幕看起来一模一样。

所以,这是基本的东西。

java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

Mac OS 10.9.5

只是好奇有没有其他人看到这个并有建议。

编辑:我下载了示例,这显然与 Modena 主题有关。里海主题看起来不错。下面是 Modena.jar TextFields 部分的屏幕截图。有趣的是,TextArea 也遇到了类似的问题,尽管不像TextField 那样普遍。

更多补充:

人们一直要求这样做,所以就在这里。我基本上只是遵循这个:https://docs.oracle.com/javafx/2/get_started/form.htm 并使用默认的 Netbeans 8.0.2 JavaFX 应用程序项目。只需从网站上剪切并粘贴即可。

public class Fxlinetest extends Application {

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("JavaFX Welcome");

        GridPane grid = new GridPane();
        grid.setAlignment(Pos.CENTER);
        grid.setHgap(10);
        grid.setVgap(10);
        grid.setPadding(new Insets(25, 25, 25, 25));

        Text scenetitle = new Text("Welcome");
        scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
        grid.add(scenetitle, 0, 0, 2, 1);

        Label userName = new Label("User Name:");
        grid.add(userName, 0, 1);

        TextField userTextField = new TextField();
        grid.add(userTextField, 1, 1);

        Label pw = new Label("Password:");
        grid.add(pw, 0, 2);

        PasswordField pwBox = new PasswordField();
        grid.add(pwBox, 1, 2);

        Button btn = new Button("Sign in");
        HBox hbBtn = new HBox(10);
        hbBtn.setAlignment(Pos.BOTTOM_RIGHT);
        hbBtn.getChildren().add(btn);
        grid.add(hbBtn, 1, 4);

        final Text actiontarget = new Text();
        grid.add(actiontarget, 1, 6);

        Scene scene = new Scene(grid, 300, 275);
        primaryStage.setScene(scene);

        primaryStage.show();
    }

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

java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)

这是来自 ScenicView 8.6 的 ThreeDOM 视图的屏幕截图,请注意以下行:

java version "1.8.0_74"
Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode)

这是使用 Caspian 主题的示例屏幕:

    System.setProperty("javafx.userAgentStylesheetUrl", "caspian");

【问题讨论】:

  • 有什么有趣的 CSS 吗?
  • 由于某种原因,似乎绘制了上升线。奇怪。
  • 当你download the samples and start the javafx ensemble时它是什么样子的?
  • 好吧,这真的很奇怪。你是如何设置你的应用程序的?有什么明确的设置吗?
  • 也许您可以提供更多代码?所以我们可以看一下......(或尝试在自己的机器上重现问题)

标签: java javafx textbox


【解决方案1】:

这是known unresolved bug

问题似乎是开发人员无法重现它。

在错误报告的 cmets 中建议使用 jvm 参数:

-Dprism.disableRegionCaching=true

但是,如果有人能够重现这个非常罕见的错误,我的建议是:

  • 修改 modena css 文件,直到错误得到解决并共享该信息。这可能会有所帮助,因为里海似乎有效。
  • 如有必要,调试到 javafx 源以隔离问题。但是,问题可能会更深,但值得一试

【讨论】:

    【解决方案2】:

    Emm...我不是 100% 确定,因为虽然我有 Linux 平台,但我对我的 jvm 没有影响;但是我仍然尝试效仿(?不确定我是否成功了)无论如何我猜你描述的问题可能真的与

    • a) 字体
    • b) 重绘问题

    您表示的代码我稍作修改,以显示如果组件位于“某些”顺序,网格面板行会发生什么情况;

    import javafx.application.Application;
    import javafx.geometry.Insets;
    import javafx.geometry.Pos;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.control.Label;
    import javafx.scene.control.TextField;
    import javafx.scene.layout.GridPane;
    import javafx.scene.layout.HBox;
    import javafx.scene.text.Font;
    import javafx.scene.text.FontWeight;
    import javafx.scene.text.Text;
    import javafx.stage.Stage;
    
    
    public class BlackLineIssueJavaFXApplication1 extends Application {
    
    
    
        @Override
        public void start(Stage primaryStage) {
    
            System.setProperty("javafx.userAgentStylesheetUrl", "Modena");
            //Modena,caspian
            primaryStage.setTitle("JavaFX Welcome");
    
            GridPane grid = new GridPane();
            grid.setAlignment(Pos.CENTER);
            grid.setHgap(10);
            grid.setVgap(10);
            grid.setPadding(new Insets(25, 25, 25, 25));
    //        grid.setGridLinesVisible(false);//<---
    
            Text scenetitle = new Text("Welcome");//original
    //        Label scenetitle = new Label("Welcome");//modified
            scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));//original
    //        scenetitle.setFont(Font.font("Verdana", FontWeight.LIGHT, 30));//modified
            grid.add(scenetitle, 0, 0, 2, 1);//original
    //        grid.add(scenetitle, 0, 0);//modified
    
    
            Label userName = new Label("User Name:");//original
    //        Text userName = new Text("User Name:");
    //        userName.setFont(Font.font("Tahoma", FontWeight.NORMAL, 11));
    
    //        grid.add(userName, 0, 1);//original
            grid.add(userName, 0, 1,1,2);//modified
    
    
            grid.setGridLinesVisible(true);//<---
    
            TextField userTextField = new TextField();  
    //        userTextField.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));//modified
            userTextField.setOpacity(0.5);//<----
    
    //        grid.add(userTextField, 1, 1);//original
            grid.add(userTextField, 1, 1,1,2);//modified
    
            grid.setGridLinesVisible(false);//<---
    
    
    
            Button btn = new Button("Sign in");
            HBox hbBtn = new HBox(10);
    
            hbBtn.setAlignment(Pos.BOTTOM_RIGHT);
            hbBtn.getChildren().add(btn);
            grid.add(hbBtn, 1, 4);//original
            //grid.add(hbBtn, 1, 3);//modified
    
            final Text actiontarget = new Text();
            grid.add(actiontarget, 1, 6);
    
            Scene scene = new Scene(grid, 300, 275);
            primaryStage.setScene(scene);
    
            primaryStage.show();
        }
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            launch(args);
        }
    
    }
    

    正在运行的应用程序如下所示:

    图片A:

    ...所以黑线出现在文本字段中大约 10px 的距离可能只是因为 Vgap 设置为 10;此外,看到“欢迎”文本是交叉的,但有垂直线;我测试了 scenetitle 的“不使用字体”是否正确(见图);

    图片 B

    所以我猜 GridPane 可能有问题;也许默认的 GridPane 有 "lines visible" 或其他东西,但是在组件添加了“disposed”行之后,但由于 TextField 应该包含“text”和“font”(参见图片 A vertical lines由于字体而导致交叉文本)重绘无法正常工作,您可以看到顶部的黑线,如图 A 所示;我不能完全模仿这种效果,但我仍然可以建议“未处理”线可能来自哪里或其他东西:)

    无论如何,我将尝试进一步分析,我在此答案中描述的信息可能会帮助您找到从哪里开始调试;

    如果您需要更多信息,请告诉我;

    祝你好运:)

    我用来测试的工具包:

    • jdk-1.0.8_25
    • jre-1.8.0_60 (Linux x64)
    • ide:netbeans 8.0.1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多