java - Swing Cannot see Horizontal scroll bar -
i want have horizontal scroll bar view whats there in "description" column.
when data in 2nd column exceeds want have horizontal scrollbar appear. code: =========working example===============
import java.awt.*; import javax.swing.*; import javax.swing.plaf.basic.basicborders.marginborder; import javax.swing.plaf.metal.metalborders.tableheaderborder; import javax.swing.table.*; import javax.swing.border.*; public class tablerowrenderingtip extends jpanel { static object[] columnnames = {"allowed commands", "description"}; private final static dimension scrollpanedimenssion = new dimension(70, 200); public tablerowrenderingtip() { object[][] data = { {"one", "allow proxies act tunnels allow proxies act tunnels allow proxies act tunnels for"}, {"two", "allow proxies act tunnels allow proxies act tunnels allow proxies act tunnels for"}, {"three","allow proxies act tunnels allow proxies act tunnels allow proxies act tunnels for" }, {"four", "allow proxies act tunnels allow proxies act tunnels allow proxies act tunnels for"}, }; defaulttablemodel model = new defaulttablemodel(data, columnnames); add( createdata(model) ); } private static jcomponent createdata(final defaulttablemodel model) { jtable inlinetable = new jtable( model ); inlinetable.setshowgrid(false); inlinetable.setshowverticallines(false); inlinetable.getcolumn(columnnames[0]).setmaxwidth(130); inlinetable.getcolumn(columnnames[0]).setminwidth(130); inlinetable.getcolumn(columnnames[0]).setresizable(false); inlinetable.getcolumn(columnnames[1]).setminwidth(270); inlinetable.setautoresizemode(jtable.auto_resize_last_column); jscrollpane scrollpane = new jscrollpane(inlinetable); scrollpane.setminimumsize(scrollpanedimenssion); scrollpane.sethorizontalscrollbarpolicy(scrollpaneconstants.horizontal_scrollbar_as_needed); return scrollpane; } public static void main(string[] args) { swingutilities.invokelater(new runnable() { @override public void run() { createandshowgui(); } }); } public static void createandshowgui() { jframe.setdefaultlookandfeeldecorated(true); jframe frame = new jframe(); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.add( new tablerowrenderingtip() ); frame.pack(); frame.setlocationrelativeto(null); frame.setvisible(true); } }
================================================== scrollpane
size fixed: want see data in 2nd column using horizontal scroll bar
Comments
Post a Comment