JTable Horizontal Scrollbar

K

Kevin Munro

Hello, I'm writing an app for a pda and I want a horizontal scrollbar on my
JTable.

I can get a vertical scrollbar by default in the following code but can't
see how to get a horizontal one.

Alternatively I was thinking of setting the RowHeight higher for those lines
that need it but can't see how to get the text to wrap.

Any ideas?

Any help much appreciated.

Kevin

import java.awt.*;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;

public class testTable extends JFrame {

String[] colNames = {"Work Order", "Customer"};
Object[][] data = {
{"290001", "Bean Pole Services Ltd"},
{"290002", "Ben Brown and his Band of Brothers"},
{"290003", "North Pole Inc"},
{"290004", "Ally's Tilers"},
{"290005", "Cakes are them"}
};

JTable table = new JTable(new DefaultTableModel(data, colNames));

public testTable() {
Container c = getContentPane();
c.add(new JScrollPane(table));
this.setSize(200,100);
this.setVisible(true);

// how to get a horizontal scrollbar?
// or, alternatively to wrap text?
table.setRowHeight(1,32);
}

public static void main(String[] args) {
testTable testTable1 = new testTable();
}
 
C

Christian Kaufhold

Crosspost, followup-to clj.gui.

Kevin Munro said:
Hello, I'm writing an app for a pda and I want a horizontal scrollbar on my
JTable.

I can get a vertical scrollbar by default in the following code but can't
see how to get a horizontal one.
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

Alternatively I was thinking of setting the RowHeight higher for those lines
that need it but can't see how to get the text to wrap.

Use a custom renderer.



Christian
 
K

Ken Clark

On Wed, 28 Jan 2004 15:33:39 -0000, "Kevin Munro"

try this:

JScrollPane tablePane = new JScrollPane( table );

tablePane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

tablePane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
 
K

Kevin Munro

I get the scrollbars but they don't scroll.

Thanks though.

Kevin.


Ken Clark said:
On Wed, 28 Jan 2004 15:33:39 -0000, "Kevin Munro"

try this:

JScrollPane tablePane = new JScrollPane( table );

tablePane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);tablePane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWA
YS);
Hello, I'm writing an app for a pda and I want a horizontal scrollbar on my
JTable.

I can get a vertical scrollbar by default in the following code but can't
see how to get a horizontal one.

Alternatively I was thinking of setting the RowHeight higher for those lines
that need it but can't see how to get the text to wrap.

Any ideas?

Any help much appreciated.

Kevin

import java.awt.*;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;

public class testTable extends JFrame {

String[] colNames = {"Work Order", "Customer"};
Object[][] data = {
{"290001", "Bean Pole Services Ltd"},
{"290002", "Ben Brown and his Band of Brothers"},
{"290003", "North Pole Inc"},
{"290004", "Ally's Tilers"},
{"290005", "Cakes are them"}
};

JTable table = new JTable(new DefaultTableModel(data, colNames));

public testTable() {
Container c = getContentPane();
c.add(new JScrollPane(table));
this.setSize(200,100);
this.setVisible(true);

// how to get a horizontal scrollbar?
// or, alternatively to wrap text?
table.setRowHeight(1,32);
}

public static void main(String[] args) {
testTable testTable1 = new testTable();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top