开发者

single column of JTable into a scroll pane

Can 开发者_开发知识库we add a single column of a JTable inside a scroll pane?


If you are asking about a horizontal scroll bar on just a single column, the following technique (viewport tweaking) will probably do the trick:

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


Not directly. One way of doing it is to create a model for both of them. Say you have a model for JTable

public class MyTableModel implements TableModel, ListModel {

Then you set the model to your JTable and your JList.


Your question really doesn't make any sense to me so I'm just making a wild guess

A TableModel can be used by many tables. So you can easily create a JTable using a TableModel. Then you can use the TableColumnModel to remove TableColumns from the view. Therefore only a single column will be visible in the scrollpane.

Edit:

To scroll horizontally you use:

table.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜