java - How to place image in a tab so that it looks like an icon -


i trying add image tab looks icon.i want put png image on tab (check image)they 4 tabs within tabbed pane
possible in java?

jtabbedpane allows provide component act tab "renderer" (of sorts).

take @ jtabbedpane#settabcomponentat more details , check out this example more details.

updated example

enter image description here

import java.awt.borderlayout; import java.awt.eventqueue; import java.io.ioexception; import java.util.logging.level; import java.util.logging.logger; import javax.imageio.imageio; import javax.swing.imageicon; import javax.swing.jframe; import javax.swing.jlabel; import javax.swing.jpanel; import javax.swing.jtabbedpane; import javax.swing.uimanager; import javax.swing.unsupportedlookandfeelexception;  public class testtabbedpaneicon {      public static void main(string[] args) {         new testtabbedpaneicon();     }      public testtabbedpaneicon() {         eventqueue.invokelater(new runnable() {             @override             public void run() {                 try {                     uimanager.setlookandfeel(uimanager.getsystemlookandfeelclassname());                 } catch (classnotfoundexception | instantiationexception | illegalaccessexception | unsupportedlookandfeelexception ex) {                 }                  jtabbedpane tp = new jtabbedpane();                 tp.addtab("dates", new jpanel());                 tp.addtab("deliveries", new jpanel());                 tp.addtab("exports", new jpanel());                  tp.settabcomponentat(0, getlabel("dates", "/icon03.png"));                 tp.settabcomponentat(1, getlabel("deliveries", "/icon01.png"));                 tp.settabcomponentat(2, getlabel("exports", "/icon02.png"));                  jframe frame = new jframe("testing");                 frame.setdefaultcloseoperation(jframe.exit_on_close);                 frame.setlayout(new borderlayout());                 frame.add(tp);                 frame.pack();                 frame.setlocationrelativeto(null);                 frame.setvisible(true);             }         });     }      protected jlabel getlabel(string title, string icon) {         jlabel label = new jlabel(title);         try {             label.seticon(new imageicon(imageio.read(getclass().getresource(icon))));         } catch (ioexception ex) {             ex.printstacktrace();         }         return label;     } } 

Comments