Single column JTable in scrollbar

Is it possible to add one JTable column inside a scrollbar?

+2


a source to share


3 answers


If you are asking for a horizontal scrollbar on only one column, the following method (customizing the viewport) will probably do the trick:



http://www.java2s.com/Code/Java/Swing-Components/FixedTableColumnExample.htm

+2


a source


Not directly. One way to do this is to create a model for both of them. Let's say you have a model for a JTable

public class MyTableModel implements TableModel, ListModel {

      



Then you will install the model for JTable

and JList

.

+1


a source


Your question really doesn't make any sense to me, so I just make a wild tick

TableModel can be used by many tables. This way you can create JTable easily with TableModel. Then you can use the TableColumnModel to remove the TableColumns from the view. Therefore, only one column will be displayed in the scroll.

Edit:

To scroll horizontally, you use:

table.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );

      

Then you set the TableColumn to your preferred width and a scrollbar will appear if needed. Read the JTable API and follow the Swing tutorial link on "How to Use Tables" for more information on setting column widths.

+1


a source







All Articles