72

So, cutting my teeth on JavaFX, so far things are moving along fine.

However, all of the text fields have a line running across them, 10px or so from the top.

Not just in my application, but in the SceneBuilder application as well.

Note, I'm not using any explicit CSS, I don't know what SceneBuilder uses. The screen shot is from SceneBuilder, my screens look identical.

JavaFX TextFields

So, it's something fundamental.

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)

On Mac OS 10.9.5

Just curious if anyone else has seen this and has a suggestion.

Edit: I downloaded the samples, it's clearly something to do with the Modena theme. The Caspian theme looks just fine. Below is a screenshot from the Modena.jar TextFields section. It's interesting that the TextArea suffers a similar issue, though not as universally as the TextField.

Modena.jar screenshot

More addenda:

Folks keep clamoring for this, so here it is. I essentially just followed this: https://docs.oracle.com/javafx/2/get_started/form.htm and use a default Netbeans 8.0.2 JavaFX Application project. Just cut and pasted it in from the website.

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);
    }
}

Sample Form Screenshot

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)

Here's is a screen shot of the ThreeDOM view from ScenicView 8.6, notice the line: ThreeDOM view from ScenicView -- notice the line

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)

Here's the sample screen using the Caspian theme via:

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

Caspian Theme view

Will Hartung
  • 115,893
  • 19
  • 128
  • 203
  • 2
    Any interesting CSS? – Evan Knowles Jun 07 '15 at 20:48
  • 1
    Looks like for some reason the ascender line is drawn. Strange. – isnot2bad Jun 07 '15 at 21:03
  • That's... odd. I'm running on the same system and have the same JDK installed; I've never seen that. Does it happen under different JDKs? (E.g. [this one](https://jdk8.java.net/download.html)) – James_D Jun 07 '15 at 21:57
  • Does setting the system property `prism.order` to `sw` (on the command line, or at least before initializing your Application) help? – VGR Jun 07 '15 at 23:16
  • I put System.setProperty("prism.order", "sw"); in the main(...), it had no affect @VGR – Will Hartung Jun 08 '15 at 00:43
  • The JDK appears to have had no noticeable affect either, @James_D – Will Hartung Jun 08 '15 at 00:47
  • 3
    How does it look like when you [download the samples and start the javafx ensemble](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)? – Roland Jun 08 '15 at 06:24
  • 1
    Okay thats realy strange. How did you setup your Application ? Anything explicit setted? – Marcel Jun 08 '15 at 11:34
  • @Roland, I added a new screenshot. – Will Hartung Jun 08 '15 at 15:01
  • @Marcel, my app is the simplest of Java FX demos, so it's all default behavior. – Will Hartung Jun 08 '15 at 15:02
  • Maybe difference between height and line-height (indeed it looks like the ascender)? Maybe the **font** on your machine? – Joop Eggen Jun 08 '15 at 15:11
  • Did you tried an older JDK/JRE, maybe its an bug. You can change the Font of the Textfields, as @JoopEggen said maybe the Default Font is broken on your machine. You can also check your graphic driver (Update). – Marcel Jun 09 '15 at 08:23
  • Does [Scenic View](http://fxexperience.com/scenic-view/) show anything useful? – ruckc Jul 05 '15 at 17:11
  • 6
    Maybe you could provide some more code? So we can take a look at it... (or try to reproduce the issue on own machines) – rzo1 Jul 22 '15 at 07:48
  • Try this maybe: http://stackoverflow.com/questions/26555828/how-to-populate-tableview-dynamically-with-fxml-and-javafx/26555829#26555829 – Chiranjib Jan 05 '16 at 09:44
  • Yeah, that's pretty weird. We could help a lot more if you could **supply us with your code**. – John S. Jan 22 '16 at 01:08
  • He mentioned that it's also happening in the samples, so seeing his code won't help. – Sam Jan 23 '16 at 23:32
  • @WillHartung Please edit your question, add how did you built the sample, the command-line with options, or IDE name & version, or did you just downloaded the jar file from a website. – Khaled.K Jan 24 '16 at 08:59
  • @WillHartung also make sure you set the theme correctly in your project, not import classes from the JAR directly, check http://stackoverflow.com/a/17380637/2128327 – Khaled.K Jan 24 '16 at 09:02
  • Maybe the issue is connected to you windows manager or library connected to them and inter-waved with JVM. Changing zoom and resolution nothing happens ? Please open a terminal and make the debug with `trace` or `strace` command, it is assembler and it gives you more debug informations. Otherwise, create a virtual machine with other OS and run the same code, not compile again, only run. – Giorgio Desideri Feb 05 '16 at 09:14
  • Have you tried this on another PC to make sure that this is not just an environmental issue – Jacques Ramsden Feb 08 '16 at 14:32
  • Still happening for you? That's odd. Did you try ScenicView in order to find out where the style comes from? – Roland Feb 13 '16 at 14:56
  • @Roland I fired that up, can't say exactly what I'm looking for here. The style class is "text-field text-input". Dunno where to see the style definitions. I ran ScenicView by calling it from within the sample I posted above. I will also say that ScenicView's text fields suffer the same issue. I just updated to _74, and the issue remains. I also see the line in the 3D view on the TextField (that 3D view is pretty cool). I assume given the number of upvotes (and views), others and experiencing this as well. – Will Hartung Feb 13 '16 at 16:30
  • Can you check if the default Stylesheet of your java is corrupt? You can set for example https://gist.githubusercontent.com/maxd/63691840fc372f22f470/raw/947157085127d367ed42ebc98d170ef7e58b40b1/modena.css into `Application.setUserAgentStylesheet()`. – eckig Feb 13 '16 at 17:11
  • @eckig Since the behavior is consistent across at least 3 versions of the JVM, I doubt its a corrupt CSS. That said, i did try your URL and had the same result. Also, I've attached a version using the Caspian theme, which appears ok. I mentioned this detail before. Thanks though, for the suggestion. – Will Hartung Feb 14 '16 at 02:14
  • 1
    @Will Hartung: If the Caspian is okay while the Modena isn't, it should be possible to find out the cause. Just change parts of the styles (also colors, line heights, etc) until you can find the culprit. There isn't that much to test. Of course there could also be some calculation being wrong, in that case one would have to debug using the JavaFX source. Once the problem is found you can file a bug report. Unfortunately I can't reproduce this on my system, So I'm of no help other than suggesting things. – Roland Feb 14 '16 at 05:22

2 Answers2

7

This is a known unresolved bug.

The problem seems to be that it isn't reproducible for the developers.

In the comments of the bug report the use of a jvm parameter is suggested:

-Dprism.disableRegionCaching=true

However, if anyone is able to reproduce this very rare bug, my suggestion is to:

  • modify the modena css file until the bug is resolved and share that information. it may help since caspian seems to work.
  • if necessary debug into the javafx source to isolate the issue. however, the problem might run deeper, but it's worth a shot
Roland
  • 18,114
  • 12
  • 62
  • 93
1

Emm... I am not 100% sure cause I don't have the effect on my jvm though I have Linux platform; But still I tried to emulate (? not sure I succeeded pretty well) anyways I guess the issue you describe may be really related to

  • a) font
  • b) repaint problem

The code you represented I modified a bit to show what happens to gridpanel lines if components located in "some" order;

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);
    }

}

The running app looks like that :

Image A :

enter image description here

...so the black line appears in text field in distance about 10px maybe just because the Vgap set to 10; Moreover, see the "welcome" text is crossed but with vertical lines; I tested if "not to use font" for scenetitle it located correctly (see image);

Image B

enter image description here

So something is maybe wrong with GridPane I guess; Maybe the default GridPane has "lines visible" or something but after components added the lines "disposed" but because of TextField which should contain "text" with "font" (see image A vertical lines cross text because of the font) the repaint doesn't work properly and you can see the black line at the top as image A shows; I cannot emulate the effect totally but still I may suggest where the "un-disposed" line may come from or something :)

I'll try to analyse a bit further anyways the info I describe in this answer may help you to find where to start debugging;

If you need some additional information please let me know;

Good luck :)

toolkit I used to test :

  • jdk-1.0.8_25
  • jre-1.8.0_60 (Linux x64)
  • ide : netbeans 8.0.1
user390525
  • 263
  • 1
  • 2
  • 18