0

so I've searched up on this How do I put html in a JLabel in java?, and so far I've come up with this:

String labelText ="<html><FONT COLOR=RED>Red</FONT> and <FONT COLOR=BLUE>Blue</FONT> Text</html>";
 JLabel coloredLabel =new JLabel(labelText);

note that i did not make this code, this was an answer off that question.

So far that's good, but how would i take it off the website and into that?

I've go this:

JLabel res;
res = new JLabel("<html>" + the code i got from the internet using JauntApi + "</html>");
panel.add(res);

so far, nothing is showing, which makes me think (and is kind of obvious) that i did something wrong. But yet, when i do this:

System.out.println(code from internet); 

It works perfectly fine and prints out the html.

So, my problem is: how do i take the html and put it on that JPanel? Thanks, and sorry for not being very clear; I suck at explaining.

Note that i want it to look like the actual website, not just a bunch of html tags.

My whole code?

public static void main(String[] args){

    final JFrame frame = new JFrame("MobaGuideLOL");
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBounds(200, 200, 600, 600);
    JPanel panel = new JPanel();
    frame.add(panel);
    JLabel res;

    try{

        UserAgent userAgent = new UserAgent();                       
        userAgent.visit("http://www.mobafire.com/league-of-legends/ahri-guide");                        
        System.out.println(userAgent.doc.innerHTML()); 
        res = new JLabel("<html>" + userAgent.doc.innerHTML() + "</html>");
        panel.add(res);

    }catch(JauntException e){

        System.err.println(e);

    }
}

it's a guide for league of legends just saying

Community
  • 1
  • 1
ruyili
  • 694
  • 10
  • 25
  • 1
    Maybe try a `JEditorPane`, seen [here](https://docs.oracle.com/javase/tutorial/uiswing/components/text.html), or an embedded JavaFX `WebView`, shown [here](http://stackoverflow.com/q/31574311/230513). – trashgod Aug 01 '15 at 16:13
  • 1
    *"Taking html from a website, .."* There is **no** Swing API that is designed for displaying web pages. Don't let the 'HTML rendering' ability fool you, the Swing HTML API is built to support a *subset* of *HTML 3.2* (HTML *4* was introduced in 1997!), *limited* CSS & ***no*** Javascript. For the ability to render web pages, look to the Java-FX `WebView` or a dedicated (3rd party) Swing based HTML component. – Andrew Thompson Aug 01 '15 at 22:26

0 Answers0