Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>public class LabelJarSample { public static void main(String args[]) { String title = "JLabel Sample"; JFrame frame = new JFrame(title); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = frame.getContentPane(); content.setLayout(new GridLayout(2, 2)); JLabel label1 = new JLabel("Text Label"); content.add(label1); Image warnImage = ImageLoader.getImage(LabelJarSample.class, "Warn.gif"); Icon warnIcon = new ImageIcon(warnImage); JLabel label2 = new JLabel(warnIcon); content.add(label2); JLabel label3 = new JLabel("Warning", warnIcon, JLabel.CENTER); content.add(label3); String htmlLabel = "&lt;html&gt;&lt;sup&gt;HTML&lt;/sup&gt; &lt;sub&gt;&lt;em&gt;Label&lt;/em&gt;&lt;/sub&gt;&lt;br&gt;" + "&lt;font color=\"#FF0080\"&gt;&lt;u&gt;Multi-line&lt;/u&gt;&lt;/font&gt;"; JLabel label4 = new JLabel(htmlLabel); content.add(label4); frame.setSize(300, 200); frame.setVisible(true); } } final class ImageLoader { private ImageLoader() { } public static Image getImage(Class relativeClass, String filename) { Image returnValue = null; InputStream is = relativeClass.getResourceAsStream(filename); if (is != null) { BufferedInputStream bis = new BufferedInputStream(is); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { int ch; while ((ch = bis.read()) != -1) { baos.write(ch); } returnValue = Toolkit.getDefaultToolkit().createImage( baos.toByteArray()); } catch (IOException exception) { System.err.println("Error loading: " + filename); } } return returnValue; } } </code></pre> <p>ref:http://www.java2s.com/Code/Java/Swing-JFC/LabelwithImage.htm</p> <p>note: also check the image location path is correct</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload