Tuesday, 15 July 2014

java - JScrollPane doesn't work/show scroll Bars -



java - JScrollPane doesn't work/show scroll Bars -

i have jframe, contains jpanel, contains jscrollpane, contains jpanel, 2 components (jpanels). reason, when utilize windowbuilder's preview alternative see frame, jscrollpane shows horizontal scroll bar, when compile , run app, doesn't. here looks like:

from preview option:

when it's compiled:

here code:

package home; import java.awt.eventqueue; import javax.swing.jframe; import java.awt.systemcolor; import javax.swing.jpanel; import javax.swing.springlayout; import javax.swing.uimanager; import net.miginfocom.swing.miglayout; import javax.swing.jlabel; import javax.swing.swingconstants; import java.awt.component; import java.awt.borderlayout; import java.awt.frame; import com.jgoodies.forms.layout.formlayout; import com.jgoodies.forms.layout.columnspec; import com.jgoodies.forms.layout.rowspec; import com.jgoodies.forms.factories.formfactory; import javax.swing.grouplayout; import javax.swing.grouplayout.alignment; import javax.swing.jbutton; import javax.swing.layoutstyle.componentplacement; import javax.swing.unsupportedlookandfeelexception; import java.awt.font; import javax.swing.boxlayout; import java.awt.event.actionlistener; import java.awt.event.actionevent; import java.awt.event.windowadapter; import java.awt.event.windowevent; import java.awt.color; import java.awt.dimension; import java.io.serializable; import java.util.arraylist; import java.util.list; import java.util.random; import javax.swing.imageicon; import javax.swing.jscrollpane; import javax.swing.border.etchedborder; import javax.swing.border.lineborder; import javax.swing.scrollpaneconstants; public class atmmaneger implements serializable { private jframe frmatmmaneger; public int numofopenatmmachines = 0; private final atmmaneger frame = this; private arraylist<atmmachine> atms = new arraylist<atmmachine>();//array list of atm machines opened private atmaccountdatabase atmdatabase = new atmaccountdatabase(); private jlabel contlabel = null; /** * launch application. */ public static void main(string[] args) { eventqueue.invokelater(new runnable() { public void run() { seek { atmmaneger window = new atmmaneger(); window.frmatmmaneger.setvisible(true); } grab (exception e) { e.printstacktrace(); } } }); } /** * create application. */ public atmmaneger getframe() { homecoming this.frame; } public atmmaneger() { initialize(); } /** * initialize contents of frame. */ private void initialize() { seek { uimanager.setlookandfeel(uimanager.getsystemlookandfeelclassname()); } grab (classnotfoundexception e1) { // todo auto-generated grab block e1.printstacktrace(); } grab (instantiationexception e1) { // todo auto-generated grab block e1.printstacktrace(); } grab (illegalaccessexception e1) { // todo auto-generated grab block e1.printstacktrace(); } grab (unsupportedlookandfeelexception e1) { // todo auto-generated grab block e1.printstacktrace(); } frmatmmaneger = new jframe(); frmatmmaneger.setminimumsize(new dimension(615, 420)); frmatmmaneger.getcontentpane().setbackground(systemcolor.activecaption); jpanel mainpanel = new jpanel(); mainpanel.setpreferredsize(new dimension(10, 10)); frmatmmaneger.setcontentpane(mainpanel); jscrollpane scrollpane = new jscrollpane(); mainpanel.add(scrollpane, borderlayout.center); jpanel subpanel = new jpanel(); subpanel.setsize(new dimension(1190, 350)); subpanel.setbackground(systemcolor.activecaption); subpanel.setpreferredsize(new dimension(1190, 350)); scrollpane.setviewportview(subpanel); subpanel.setlayout(new miglayout("", "[50.00%,grow][50.00%,grow]", "[grow]")); jpanel panel = new jpanel(); subpanel.add(panel,"cell 0 0,grow"); panel.setborder(null); panel.setbackground(systemcolor.texthighlight); panel.setlayout(new miglayout("", "[100.00%,grow]", "[71px][13.54%][10.09%][41px][][grow]")); jpanel panel_1 = new jpanel(); subpanel.add(panel_1, "cell 1 0,grow"); frmatmmaneger.settitle("atm maneger"); frmatmmaneger.setbounds(700, 400, 609, 420); frmatmmaneger.setdefaultcloseoperation(jframe.exit_on_close); } }

i made app similar one, 1 inherents jframe. couldn't find difference between code , 1 above. code:

package home; import java.awt.borderlayout; import java.awt.eventqueue; import javax.swing.jframe; import javax.swing.jpanel; import javax.swing.uimanager; import javax.swing.border.emptyborder; import javax.swing.jscrollpane; import java.awt.color; import java.awt.flowlayout; import net.miginfocom.swing.miglayout; import java.awt.dimension; import javax.swing.jlabel; import javax.swing.jbutton; public class test02 extends jframe { private jpanel contentpane; /** * launch application. */ public static void main(string[] args) { eventqueue.invokelater(new runnable() { public void run() { seek { test02 frame = new test02(); frame.setvisible(true); } grab (exception e) { e.printstacktrace(); } } }); } /** * create frame. */ public test02() { seek { uimanager.setlookandfeel(uimanager.getsystemlookandfeelclassname()); } grab (exception e) { // handle exception } setdefaultcloseoperation(jframe.exit_on_close); setbounds(100, 100, 432, 300); contentpane = new jpanel(); contentpane.setborder(new emptyborder(5, 5, 5, 5)); contentpane.setlayout(new borderlayout(0, 0)); setcontentpane(contentpane); jscrollpane scrollpane = new jscrollpane(); contentpane.add(scrollpane, borderlayout.center); jpanel panel = new jpanel(); panel.setpreferredsize(new dimension(800, 220)); panel.setbackground(color.red); scrollpane.setviewportview(panel); panel.setlayout(new miglayout("", "[50.00%,grow][50.00%,grow]", "[grow]")); jpanel panel_1 = new jpanel(); panel.add(panel_1, "cell 0 0,grow"); panel_1.setlayout(new miglayout("", "[][][][][][][]", "[][][][][][]")); jlabel lblnewlabel = new jlabel("new label"); panel_1.add(lblnewlabel, "cell 2 1"); jbutton btnnewbutton_1 = new jbutton("new button"); panel_1.add(btnnewbutton_1, "cell 3 3"); jbutton btnnewbutton = new jbutton("new button"); panel_1.add(btnnewbutton, "cell 2 5"); jlabel lblnewlabel_1 = new jlabel("new label"); panel_1.add(lblnewlabel_1, "cell 6 5"); jpanel panel_2 = new jpanel(); panel.add(panel_2, "cell 1 0,grow"); } }

so it's silly mistake, it?

i don't see changing scrollbar policy. since there no overflow, without changing setting, not see scrollbar appear.

try:

scrollbar.setverticalscrollbarpolicy(jscrollpane.vertical_scrollbar_always);

java swing jscrollpane miglayout preferredsize

No comments:

Post a Comment