0

I am trying to create a clone of Web Browser using Swing. I have used JEditorPane but for some reason the background color is always in blue color. This is what I have done

JEditorPane editor = new JEditorPane();
editor.setEditable(false);
editor.addHyperlinkListener(this);
editor.setBackground(Color.WHITE);
try{
    editor.setPage("https://www.google.com");
}catch(Exception e){}

and
this is what I am getting as result

I don't want to use JavaFx, is there any way how we can fix this using Swing only?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Kunal
  • 89
  • 4
  • 3
    Does this answer your question? [Browser using JEditorPane forcing blue background](https://stackoverflow.com/questions/22579965/browser-using-jeditorpane-forcing-blue-background) – maloomeister Nov 26 '20 at 13:12
  • *"I am trying to create a clone of Web Browser using Swing."* Swing is not up to that. It only supports a **subset** of ***HTML 3.2***, limited styles and no scripting. Use the Java-FX `WebView` - which embeds an actual browser (AFAIU). – Andrew Thompson Nov 26 '20 at 13:15
  • 2
    @AndrewThompson is using outdated software a close reason? I’d find tons of questions we could close then. But letting the background color aside, the Google page seems to be usable with Swing. Starting with JDK 13, the background color seems to be fixed too. – Holger Nov 26 '20 at 17:20
  • @Holger *"is using outdated software a close reason?"* I use Swing every other day. It fulfills my (simple) GUI needs. I never mentioned nor meant to imply it should not be used because of its age. But the context of my comments is *"clone of Web Browser"* - a direct quote from the OP. Swing's HTML support was intended for quick and easy mark-up of rich text. It was never meant to be a pseudo browser, let alone a clone of a browser. Of course it is possible to improve / expand Swing's abilities. E.G. I built support for the applet element into a `JEditorPane` .. – Andrew Thompson Nov 26 '20 at 19:12
  • .. while it was certainly possible (and putting aside that applets are no longer supported at all) if I were to do something, *anything,* similar now, I'd immediately abandon Swing & look to use a `WebView` instead. One good `WebView` example was an app to check Twitter accounts who block you, with the app able to remember accounts to offer in a list. Would not have wasted my time with a `JEditorPane` on that one. – Andrew Thompson Nov 26 '20 at 19:14
  • @AndrewThompson I was referring to the now-removed comment regarding closing. Using the wrong tool for the job or even trying to achieve an impossible goal aren’t reasons for closing either. These points could be addressed in an answer… – Holger Nov 27 '20 at 09:28

1 Answers1

0

@Kunal, Try changing the color from white to something else