Html bold in jLabel in linux

Hi,
I'm trying to put Html in a Label. However the bold isn't working under linux. In windows it works. But in linux it doesn't. I tried playing around with it. But nothing worked for me.
zText1 = "test";
zText2 = "test";
zLabel.setText("<html><font size=\"4\" face =\"Courier\"><b>" + zText1 + "</b>  " + zText2 + "</font></html>"); Thanks,
Shaul

In the future, please ask swing questions in the swing forum.
It would appear that the default font for JLabel and JButton is bold.
import java.awt.Font;
import javax.swing.JLabel;
public class BoldHtml extends javax.swing.JFrame {
    public BoldHtml() {
        final JLabel label =
            new JLabel("<html><font size=\"4\" face =\"Courier\">test <b>test</b>  <i>test</i></font></html>");
        label.setFont(label.getFont().deriveFont(Font.PLAIN));
        add(label);
        pack();
    public static void main(String args[]) {
        new BoldHtml().setVisible(true);
}

Similar Messages

  • Problem with HTML in a JLabel

    Is it possible to use styles when using HTML in a JLabel?
    Example:
    <html><hr style="height: 1px; color: black;"></html>Doesn't work correctly as this should give a solid 1px high hr, but doesn't. Instead it gives a black hr with a white shade...
    The JLabel it is used in is not customized in any way.

    I too am interested in getting color on an HR to work. Can you summarize what you have done to date? Sample code?
    Note: An easy way to correct it in a Nonframe instance of html is to subclass HTMLEditor to implement your own ViewFactory and own HRuleView which checks the attribute tag color for the color. I've got this to work, but frames don't work since you can call FrameView (not public) and thus have to use the super class - which then by-passes the ViewFactory from then on.
    So a NON-FRAME Solution to give HR color is... Anybody have a better global solution?
    Here is the one line fix to HRuleView .setProperties. So if you subclass HRuleView specifically to do
    public class MyHTMLEditorKit extends HTMLEditorKit { // StyledEditorKit
        private static final ViewFactory defaultFactory = new MyHTMLFactory();
        public static class MyHTMLFactory extends HTMLFactory {//implements ViewFactory {
             public View create(Element elem) {
             Object o = elem.getAttributes().getAttribute(StyleConstants.NameAttribute);
             if (o instanceof HTML.Tag) {
              HTML.Tag kind = (HTML.Tag) o;
              if (kind == HTML.Tag.HR) {
                  return new MyHRuleView(elem);
           return super.create(elem);
    class MyHRuleView extends View  {
         private Color color = null;
         public void setPropertiesFromAttributes() {
              super.setPropertiesFromAttributes();
              try {color = new Color(Integer.decode((String)attr.getAttribute("color")).intValue());} catch (Exception e) {}
         public void paint(Graphics g, Shape a) {
              if (color != null) g.setColor(color);
              super.paint(g, a);
    }

  • HTML on A JLabel ARRRGGGGHHHH!!!!

    Okay - I've used the functionality of putting html in a JLabel before fine, I think it's pretty useful.
    Unfortunately I've just written a modal dialog inner class where it just won't wrap at the edge of the screen, someone please tell me why...!
    Here's the code
    * Modal config dialog box.
    private class RefreshDialog extends JDialog
    private JButton _okayButton = new JButton("OK");
    private JButton _cancelButton = new JButton("Cancel");
    private String _sCurrentText;
    private JTextField _periodField;
    private JLabel _topText = new JLabel("<html><p>Changing the refresh rate will change the " +
    "frequency of chart updates. Please select from the below.</html>");
    private int _nMultiplicationFactor = 1;
    private String _sSeconds = "Seconds";
    private String _sMinutes = "Minutes";
    private String _sHours = "Hours";
    private JComboBox _unitCombo = new JComboBox(new Object []{_sSeconds, _sMinutes, _sHours});
    * Create an Update Dialog with the delay set to the specified number of seconds
    * @param parent Parent container.
    * @param nDelay the refresh rate in seconds
    public RefreshDialog(JFrame parent)
    super(parent, "Change refresh rate", true);
    this.setLocation(parent.getLocation());
    Container contentPane = this.getContentPane();
    JPanel northPanel = new JPanel();
    JPanel ratePanel = new JPanel();
    BoxLayout rateEntryLayout = new BoxLayout(ratePanel, BoxLayout.X_AXIS);
    JPanel okayCancelPanel = new JPanel();
    BoxLayout okayCancelLayout = new BoxLayout(okayCancelPanel, BoxLayout.X_AXIS);
    //calculate the default setting for delay passed in
    if ( m_nChartRefreshDelay < 60 )
    sCurrentText = String.valueOf(mnChartRefreshDelay);
    unitCombo.setSelectedItem(sSeconds);
    else if (m_nChartRefreshDelay < 3600)
    sCurrentText = String.valueOf(mnChartRefreshDelay/60.00);
    unitCombo.setSelectedItem(sMinutes);
    else
    sCurrentText = String.valueOf(mnChartRefreshDelay/3600.00);
    unitCombo.setSelectedItem(sHours);
    periodField = new JTextField(sCurrentText, 4);
    JLabel label = new JLabel("Update every ");
    _topText.setBorder(BorderFactory.createEmptyBorder(4, 3, 5, 3));
    northPanel.add(_topText);
    contentPane.add(northPanel, BorderLayout.NORTH);
    ratePanel.add(label);
    ratePanel.add(_periodField);
    ratePanel.add(_unitCombo);
    contentPane.add(ratePanel, BorderLayout.CENTER);
    okayCancelPanel.add(_okayButton);
    okayCancelPanel.add(_cancelButton);
    contentPane.add(okayCancelPanel, BorderLayout.SOUTH);
    _cancelButton.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent ae){
    RefreshDialog.this.dispose();
    _okayButton.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent ae){
    //do some action
    setResizable(true);
    this.setSize(400, 200);
    }

    Okay - I've worked it out - doesn't work in BorderLayout for some reason. Put it in a Box Layout and everything is fine......
    ..don't ask me why???

  • HTML in TreeCellRenderer (JLabel) really slow

    Hi,
    I've used HTML in my TreeCellRenderer to make the node (ie the JLabel) display a formatted text, both bold and italic + an icon. It looks great, but it's really slow. I've run it through JProbe and it seems like the call to label.setText(x) creates thousands of extra objects and is taking a lot of time. Is there a way around this?
    I've searched the forums but can't find a soultion. I also found this:
    http://developer.java.sun.com/developer/bugParade/bugs/4792592.html
    What I want is to be able to change color for each node in the tree plus use bold and italic text within the same label.
    /s

    I had this problem with setting HTML on all the cell in a JTree.
    The problem is caused by the renderer parsing the html and building a view like a JTextArea does. This is what causes the large number of objects to be created. This is done every time the cells are painted which is a big problem when scrolling the tree.
    To solve it I extended the DefaultTreeCellRenderer to cache the generated html views as they are created using the client property called "html" as follows:
    public class FastHTMLCellRenderer extends DefaultTreeCellRenderer {
        Map views = HashMap();
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean
                 selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            Object view = views.get(value);
            if(view==null) {
                // generate the html for the value
                setText("<html>....." + value + "</html>");
                views.put(value, getClientProperty("html"));
            else {
                putClientProperty("html", view);
    }This improves the performance dramatically but has the issue that the views should be removed from the cache when the values are removed from the tree model.
    This also applys to JTables and other CellRenderers.

  • HTML to PDF Conversion in Linux env

    Dear all,
    Do you have any idea how to convert HTML to PDF using java in Linux environment.
    Thanks
    SS

    HTML to PDF with Java, using OpenOffice.org - example here: [http://www.dancrintea.ro/html-to-pdf/|http://www.dancrintea.ro/html-to-pdf/]
    You can use OpenOffice.org, running as a server and command it remotely for document convertion.
    Besides HTML to PDF, there are also possible other convertions:
    doc --> pdf, html, txt, rtf
    xls --> pdf, html, csv
    ppt --> pdf, swf
    Code example:
    import officetools.OfficeFile; // this is my tools package
    FileInputStream fis = new FileInputStream(new File("c:/test.html"));
    FileOutputStream fos = new FileOutputStream(new File("c:/test.pdf"));
    // suppose OpenOffice.org runs on localhost, port 8100
    OfficeFile f = new OfficeFile(fis,"localhost","8100", true);
    f.convert(fos,"pdf");
    -----------------------------------------------------------------------------------------------------------------------------------------

  • Show HTML bold-faced fonts?

    What is the way to get some of the texts, but not all the texts, to appear bold-faced? The line below does not work. Any ideas? Maybe some HTML needed? I don't need a gigantic set of codes for all HTML. I just need to display some texts in bold.
    stingToBeBoldFaced.setFont(new Font(FontFaceBeautiful, Font.PLAIN, FontSizeBig));

    You are right. JEditorPane is the one needed. When I try searching this keyword, I found codes for displaying a web page. I did not find a single bold-faced example. Keith's example is nice.

  • Stretching of HTML table in JLabel

    Hi all,
    I am trying to display an HTML table in a JLabel. The table uses width="100%", but the html table doesn't resize according to the size of the JLabel. Is this a know issue or am I doing something wrong?
      String html = "<html> <head> </head> <body> <table border=\"2\" width=100%> <tr> <td>  test  </td> <td> test </td> <td> test </td> </tr> </table> </body> </html>";
            JLabel label = new JLabel(html);
            getContentPane().add(label, BorderLayout.CENTER);kind regards,
    Christiaan

    The JTable uses a cell renderer to draw the JLabel.
    The cell renderer figures out the size of the table cell without reading the html. Which means it ignores the width=100% when it calculates the size of the table cell. If you want the cell to resize properly, you have to implement a table cell renderer, and make that renderer set the column size or row height accordingly. That means you have to calculate the cell size yourself.
    In my opnion, i would say this is a bug, as I've had numerous problems with it too.

  • Generate a thumbnail from HTML by pure Java on Linux without Graphics

    hi - we in a requirement where we have to generate thumbnails from HTML code. The solution must be implemented in pure Java on Linux where there is no graphics support.
    Options tried already are :--
    1. 3rd party websites - rolled out by our client.
    2. Paid products - rolled out by our client
    3. Media Tracker and other java API - no luck as there is no support after HTML 4.0
    4. Using any os dependent native library - rolled out by our client.
    5. Lobo browser - but having troubles like it opens the browser before screenshot is taken, sometimes. Gone through by putting Thread.sleep() in between and saving remote images into a local html file etc. We got some success in there but problem doesn't end here.
    Questions -
    1. In the point # 5 above, our Linux server had graphics support but in code we set the system property java.awt.headless= true before capturing and generating thumbnail. My question is, if we set this property in the code then does it mean 100% that our code will not use any graphics support, if present in the underlying OS?
    2. Is this really possible to generate images in java on Linux where there is no X window/X server installed? Are we just wasting time in order to achieve which is unachievable?
    Any suggestions are most welcome.
    Regards,
    Sanjeev

    Thanks for ur response! Yeah - we tried but requirements are little different. We have HTML that we have to first render. Whatever output comes, we have to take a screenshot. So in order to render the html we have to have a browser first and I believe every OS which is providing browser support is having Graphics capabilities because browser would have frames, windows, toolbars, menubars etc which fall under Graphics.
    The above way is the only way that I know. If there are another way which ofcourse doesn't require graphics support, please let me know.
    So the question basically is - if I follow above mentioned image (like opening browser and capture screenshot) then is it possible on Linux with no graphics support? Actually I read on internet that lobo browser (written in java) supports this kind of feature.

  • Can i show an HTML text on JLabel

    Can any body help me about showing HTML text on a JLabel component!!
    Thanks.
    Neeraj

    http://forums.java.sun.com/thread.jsp?forum=57&thread=151899

  • No HTML report from ISE in linux

    Hello everybody :)
    I work with Xilinx ISE 14.7 undre linux openSUSE 13.1 bootle kernel 3.11.29. I have such a small issue. After synthesis when I want to see Design summary mainly "advanced synthersis report" and "timing details" I cannot generate or open HTML file by using of right mouse button click "View report as HTML". When I do that nothing happens. Several times I need it to immediately see and explore distincts between differrent versions of my designs and its also very helpful to see immediately and not to have to going to directory and load this files manually . The same problem persists when I want to open these interactive "warnings" messages in my console which should me immediately redirect to Xilinx website with topics related to my problems or warnings. When I have workde under Windows 7 everything worked perfectly as it should have. I mean that command for external browser under Preferences -> HTML Browser does not have to be set properly. Unfortunatelly I do not know to which value I should set it or if something else may be wrong. As browser I use Mozilla firefox 39.0 and it is set as my default browser. If anybody else would have some idea or personal experiences with this issue it would really help and I would appreciate.
    Thanks for help.                                                                  Martin :)
     

    Does Xilinx plan to do something to solve these issues related to different linux distributions to the future? I also had troubles to generate licenses for Vivado because of the same issue. Thanks?

  • How to disable html view in JLabel

    "As of Swing 1.1.1 Beta 1, JLabel supports multiple lines, multiple fonts, and a whole lot more because you can specify a label's text using HTML. "
    does any one know how to disable this feature, so that if HTML code is entered, it wont be parsed andwhat ever was entered will be displayed, as is, on the JLabel????

    I dont really have control of what is being entered.Whose program is it, then, that contains the setText() method for the JLabel? (Or creates a JLabel with some text?) If it's yours, then I don't see why you can't examine the text before you call that line of code and modify the text as suggested earlier.

  • Adding a html link to JLabel

    Hi...
    So, what I want is a JLabel or maybe a JOptionPane to have a HTML link on it to a website and if the user clicks on said link I would like their default browser to fire up and hit that page. Thus in the below code I have a JLabel with "Java" showing and underlined like it is a link...now, how do I get this event processed?
    JLabel linkLabel =
    new JLabel("<html><a href="+"http://www.java.sun.com"+">Java</html>");
    TIA
    tfm

    search is your friend:
    http://search.java.sun.com/search/java/index.jsp?col=javaforums&qp=%2Bforum%3A31&qt=hyperlink+label

  • Html link inside JLabel

    I write this code:
    String text ="<html><font size=2>Java-Editor</font>"
    +  "<P>"
    + "Homepage: <a href=\"www.b2m.it/ma\"> http://www.b2m.it</a></html>";
    JLabel textLabel = new JLabel(text);I show the jlabel inside a jdialog.
    When i press on hyperlink, the link don't work
    where is the error?

    You could use a java.awt.event.MouseListener on the label, it would be something like
    public class MyClass extends javax.swing.JFrame implements ajva.awt.event.MouseListener
         // public variables
         public MyClass()
              JLabel label = new JLabel("label text");
              label.addMouseListener(this);
              //other initializations          
         public void mouseClicked(java.awt.event.MouseEvent e)
              //handle click
         //other methods

  • An HTML-kit - like editor for Linux [SOLVED]

    In my workplace we are using Windows XP and there our editor of choice is HTML-kit. I like Gedit and Bluefish a lot in Linux but both are missing the feature I like the most in HTML-kit: the live FTP connection that makes all the files visible directly from FTP and then when I am editing them, they got directly uploaded to the FTP server. All without the need to manually ALT-TAB into an FTP client, find the proper file and upload it.
    Is there an editor that might do to the same thing in Linux?
    Last edited by sven (2007-06-02 07:57:36)

    I know this isn't exactly what you want but I use Bluefish this way:
    I have a webserver where I upload my html files to and I do all the editing and have all source files on my laptop.
    To make things easier and avoid having to do the alt-tab thing you talked about I have created a small script that I run from within Bluefish to do the upload for me. The script is very simple... something like this:
    #!/bin/bash
    lftp -u username,password 192.168.0.2 <<EOF
    cd /home/httpd/html/
    put $1
    quit 0
    EOF
    In Bluefish under preferences->external programs you can then call this script by adding it to "utilities and filters" like this:
    "/home/user/ftp_upload.sh %s"
    The last step would be to create a short-cut key so that you only have to press eg Ctrl+g, or what ever you want, to save and upload the file you are currently working on.
    This method doesn't let you browse the remote ftp directory and edit files directly, but I find it to be a very smooth way to quickly edit and upload your local files to an ftp server.

  • HTML bold text, imported from XML problem.

    I have HTML content defined in an external XML file:
    quote:
    <textBody><p>First line of text containing some
    <b>bold words</b>. More text with some <b>bold
    words</b> and then two line breaks.<br /><br
    />Here's some more text with <b>some more bold
    words</b> in the middle of it. Don't you think there's
    something strange about the spacing around these <b>bold
    words</b>? It seems to get worse with each extra appearance
    of a <b>bold word</b>. Thank you <b>for
    reading</b> my text.</p></textBody>
    Here,
    you can see a screenchot of the text rendered on screen from the
    HTML above.
    Many thanks for any help from anybody.

    We think we've got the source of the problem - because the
    textfield displaying the HTML is in a component. We believe the
    letter spacing issue comes about from the component being resized.
    The solution, as far as we can see is to simply use dynamic
    textfields instead of components - OK for future development, but
    what we've done already will need to be fixed by extra spaces in
    various places.
    Thanks for your suggestion Pal_w_g - guess it was your input
    that provided the seed that led to the idea about the component.

Maybe you are looking for

  • OBIEE 11g (11.1.1.5...)Column Selectors and Action Links

    All, I think we have bug - we have a column selector for 3 columns. One of them is configured to navigate to another analyses page (we have only one action link configured) . we have checked the option - "Do not display in a popup if only one action

  • What do I need to look for on my MacBook Pro to see if it will support Mountain Lion?

    I see some MacBooks will not be able to get Mountain Lion. Which and where can I look to find out?

  • TLF Problems

    Hi all, New here in this forum... I'm not sure if this is the right place for my question. I've recently updated my Flash CS5 (Flash Professional CS5 Update 11.0.2 09/07/2010). It seems like it has a bug in the TLF. I have a little chat app. When eve

  • Copy values form report to a record detail page.

    Hi, We have a requirement where we want a Link on the Contact report. The link when clicked will navigate us to New Task page, but along with this we want to copy the Contact information form the report to the Task record. Is this possible? Thanks

  • Searching subdirectories

    hi can anyone take a look at this code and tell me how to correct it. i am trying to search a directory and sub folders within it. public ArrayList<File> arrfiles = new ArrayList<File>(); public File[] list =  null;       public  ArrayList<File> list