Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2004

Tip: Looking for answers? Try searching our database.

JTable Horizontal Scrollbar

Thread view: 
Kevin Munro - 28 Jan 2004 10:10 GMT
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();
}

}
skateongv - 29 Jan 2004 21:27 GMT
re:"but can't see how to get the text to wrap."

           setLineWrap(true);
           setWrapStyleWord(true);

public class Welcome extends JPanel
   { // open Welcome class
       // Variables for objects
       private JTextArea ta;

       public Welcome()
       { //opens Welcome constructor
           setLayout(new BorderLayout());

           ta = new JTextArea("This application is a test");

           ta.setFont(new Font("SansSerif",  Font.PLAIN, 14));
           ta.setLineWrap(true);
           ta.setWrapStyleWord(true);
           ta.setEditable(false);
}
}

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();
}

}
Kevin Munro - 30 Jan 2004 09:14 GMT
Thanks, I was a bit confused over the custom render idea but does this just
really mean I should be putting a JTextArea inside the cells for that
column? I can see that working -- I'll have to gen up on these custom
renderers!

Kevin.

> re:"but can't see how to get the text to wrap."
>
[quoted text clipped - 67 lines]
>
> }


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.