java - JTabbedPane minimum size incorrectly calculated -
i found bug in java , i'd know what's best way workaround it.
when create jtabbedpane left alignment (the tabs on left side) , if add icons in tabs, minimum size of component incorrect.
here simple way reproduce:
import java.awt.borderlayout; import java.awt.dimension; import javax.swing.imageicon; import javax.swing.jframe; import javax.swing.jlabel; import javax.swing.jpanel; import javax.swing.jsplitpane; import javax.swing.jtabbedpane; public class minsizecomponent { // +-------------------------------- // | constructor // +-------------------------------- // +-------------------------------- // | methods // +-------------------------------- public void createandshowgui() { system.out.println("createandshowgui()"); jframe.setdefaultlookandfeeldecorated(true); jframe frame = new jframe("selection"); frame.setdefaultcloseoperation(jframe.exit_on_close); // +-----------------------------------------+ // | gathering | // +-----------------------------------------+ jpanel panel1 = new jpanel(); panel1.setminimumsize(new dimension(100, 99)); panel1.setpreferredsize(new dimension(150, 99)); jpanel panel2 = new jpanel(); panel2.setminimumsize(new dimension(200, 99)); panel2.setpreferredsize(new dimension(250, 99)); jpanel panel3 = new jpanel(); panel3.setminimumsize(new dimension(50, 99)); panel3.setpreferredsize(new dimension(250, 99)); jpanel panel4 = new jpanel(); panel4.setminimumsize(new dimension(150, 99)); panel4.setpreferredsize(new dimension(250, 99)); //with top arrangement there no problem //jtabbedpane tabbedpane = new jtabbedpane(jtabbedpane.top); //with left arrangement bug appears jtabbedpane tabbedpane = new jtabbedpane(jtabbedpane.left); //without adding icon in tabs, min size of panel correct: 200 /* tabbedpane.addtab("panel 1", null, panel1, "tip1"); tabbedpane.addtab("panel 2", null, panel2, "tip2"); tabbedpane.addtab("panel 3", null, panel3, "tip3"); tabbedpane.addtab("panel 4", null, panel4, "tip4"); */ //with icons in tabs, min size of panel incorrect: ~285 //should 200 well! tabbedpane.addtab("panel 1", new imageicon("y:/src/resources/icons/iconuser_32x32.png"), panel1, "tip1"); tabbedpane.addtab("panel 2", new imageicon("y:/src/resources/icons/iconuser_32x32.png"), panel2, "tip2"); tabbedpane.addtab("panel 3", new imageicon("y:/src/resources/icons/iconuser_32x32.png"), panel3, "tip3"); tabbedpane.addtab("panel 4", new imageicon("y:/src/resources/icons/iconuser_32x32.png"), panel4, "tip4"); jpanel rightpanel = new jpanel(); rightpanel.add(new jlabel("label right panel")); jsplitpane splitpanehorizontal = new jsplitpane(jsplitpane.horizontal_split, tabbedpane, rightpanel); jpanel core = new jpanel(new borderlayout()); core.add(splitpanehorizontal, borderlayout.center); core.setpreferredsize(new dimension(500, 500)); //display window. frame.getcontentpane().add(core); frame.pack(); frame.setvisible(true); } // +----------------------------- // | main // +----------------------------- public static void main(string[] args) { minsizecomponent toto = new minsizecomponent(); toto.createandshowgui(); } }
just execute, move split pane on left @ maximum. can see size on jtabbedpane content approximately 285 pixels. remove icons in tabs: size becomes correct: 200 pixels (which maximum of minimum size inner components).
anyone knows what's best way workaround it? many thanks,
Comments
Post a Comment