5

I try to open a webview in java and show the spotify login page. (https://accounts.spotify.com/en/login):

JFrame f = new JFrame();
    f.setTitle("Spotify");
    f.setSize(500,500);
    f.setVisible(true);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JFXPanel jfxPanel = new JFXPanel();
    f.add(jfxPanel);
    Platform.runLater(() -> {
        WebView webView = new WebView();
        jfxPanel.setScene(new Scene(webView));
        WebEngine webEngine = webView.getEngine();
        webEngine.load("https://accounts.spotify.com/en/login");
    });

The result is the window below. (when i copy the cryptic text and paste it in another application, it shows me the text with right encoding.
How can I display the spotify login page with correct encoding?

http://fs2.directupload.net/images/150909/zyk25eqz.png

Felix
  • 51
  • 5

2 Answers2

3

I saw this at the dropbox login page in my WebView, too.

The problem you encountered has nothing to do with encoding. The JavaFx WebView has some problems with loading local fonts. If you load a website which wants to load a local font installed on your computer you will see this cryptic letters. If you remove the font you will see the text as usual.

So your problem isn't the encoding of the website, it's the font spotify want's to load and you are having local on your pc.

You will have to find a way to stop the WebView from loading local fonts. Maybe by injecting some code.

Nicole
  • 41
  • 5
-1

You need to check that the encoding of the files on your project mathches with the one from the spotify server response, I already checked the spotify url you gave and is Content-Type:text/html; charset=utf-8 so, if your file is not utf8, convert it, you can do it with notepad++, on the Encoding menu.

Gabriel Rodriguez
  • 1,163
  • 10
  • 23
  • Can you clarify that? What file(s) are you talking about when you say "if your file is not utf8", and "files on your project"? – James_D Sep 09 '15 at 19:45
  • The file that you use to invoke WebView, WebEngine, etc...and all other files on your project(if they are linked to that one some how) – Gabriel Rodriguez Sep 09 '15 at 22:15
  • Those are just Java source code. They are compiled to (binary) class files containing bytecode. So they don't have an encoding, they're not even text. I'm not sure this answer makes any sense. – James_D Sep 09 '15 at 22:20
  • i looked it up and found out that eclipse choose utf-8 by default. So there must be another issue. – Felix Sep 09 '15 at 22:25
  • 1
    The encoding your source files use is completely irrelevant. The source files don't need to be present - indeed probably shouldn't be present - when the application is running. So the encoding they use cannot possibly have any effect on what happens when the application runs. – James_D Sep 09 '15 at 22:26