Name: rk38400 Date: 04/10/98
If the table autoresizes and the minimum
column size is greater than the viewport area
the horizontal scroll bars don't show up or
allow you to scroll.
Below is a short example that will show the bug.
Run it and size the window so that a column
is cut off. The horizontal scrollbar show up
but the slider has no where to go.
import com.sun.java.swing.*;
import com.sun.java.swing.table.*;
import com.sun.java.swing.event.*;
import com.sun.java.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class TableTest extends JFrame
{
public static void main( String[] args)
{
Frame f = new TableTest();
}
public TableTest()
{
super("TableTest");
this.getContentPane().add(createTable());
setSize(new Dimension(200,200));
show();
}
public JScrollPane createTable() {
// final
final String[] names = {"First\nName", "Last\nName"};
//ImageIcon burger = loadIcon("burger.gif","burger");
//ImageIcon fries = loadIcon("fries.gif","fries");
//ImageIcon softdrink = loadIcon("softdrink.gif","soft drink");
//ImageIcon hotdog = loadIcon("hotdog.gif","hot dog");
//ImageIcon pizza = loadIcon("pizza.gif","pizza");
//ImageIcon icecream = loadIcon("icecream.gif","ice cream");
//ImageIcon pie = loadIcon("pie.gif","pie");
//ImageIcon cake = loadIcon("cake.gif","cake");
//ImageIcon donut = loadIcon("donut.gif","donut");
//ImageIcon treat = loadIcon("treat.gif","treat");
//ImageIcon grapes = loadIcon("grapes.gif","grapes");
// ImageIcon banana = loadIcon("banana.gif","banana");
// ImageIcon watermelon = loadIcon("watermelon.gif","watermelon");
// ImageIcon cantaloupe = loadIcon("cantaloupe.gif","cantaloupe");
// ImageIcon peach = loadIcon("peach.gif","peach");
// ImageIcon broccoli = loadIcon("broccoli.gif","broccoli");
// ImageIcon carrot = loadIcon("carrot.gif","carrot");
// ImageIcon peas = loadIcon("peas.gif","peas");
// ImageIcon corn = loadIcon("corn.gif","corn");
// ImageIcon radish = loadIcon("radish.gif","radish");
// Create the dummy data (a few rows of names)
final Object[][] data = {
{"Mike", "Albers", Color.green, "Soccer", new Integer(44)},
{"Mark", "Andrews", Color.red, "Baseball", new Integer(2)},
{"Tom", "Ball", Color.blue, "Football", new Integer(99)},
{"Alan", "Chung", Color.green, "Baseball", new Integer(838)},
{"Jeff", "Dinkins", Color.magenta, "Football", new Integer(8)},
{"Amy", "Fowler", Color.yellow, "Hockey", new Integer(3)},
{"Brian", "Gerhold", Color.green, "Rugby", new Integer(7)},
{"James", "Gosling", Color.pink, "Tennis", new Integer(21)},
{"David", "Karlton", Color.red, "Baseball", new Integer(1)},
{"Dave", "Kloba", Color.yellow, "Football", new Integer(14),},
{"Peter", "Korn", new Color(100, 100, 255), "Scuba Diving", new Integer(12)},
{"Dana", "Miller", Color.blue, "Ice Skating", new Integer(8)},
{"Phil", "Milne", Color.magenta, "Rugby", new Integer(3)},
{"Dave", "Moore", Color.green, "Tennis", new Integer(88)},
{"Hans", "Muller", Color.magenta, "Baseball", new Integer(5)},
{"Rick", "Levenson", Color.blue, "Football", new Integer(2)},
{"Tim", "Prinzing", Color.blue, "Baseball", new Integer(22)},
{"Chester", "Rose", Color.black, "Hockey", new Integer(0)},
{"Chris", "Ryan", Color.black, "None", new Integer(6)},
{"Ray", "Ryan", Color.gray, "Football", new Integer(77)},
{"Georges", "Saab", Color.red, "Hockey", new Integer(4)},
{"Tom", "Santos", Color.blue, "Football", new Integer(3)},
{"Rich", "Schiavi", Color.blue, "Hockey", new Integer(4)},
{"Nancy", "Schorr", Color.blue, "Hockey", new Integer(8)},
{"Violet", "Scott", Color.magenta, "Basketball", new Integer(44)},
{"Joseph", "Scheuhammer", Color.green, "Hockey", new Integer(66)},
{"Jeff", "Shapiro", Color.black, "Skiing", new Integer(42)},
{"Willie", "Walker", Color.blue, "Hockey", new Integer(4)},
{"Kathy", "Walrath", Color.blue, "Baseball", new Integer(8)},
{"Arnaud", "Weber", Color.green, "Football", new Integer(993)},
{"Steve", "Wilson", Color.green, "Baseball", new Integer(7)}
};
// Create a model of the data.
TableModel dataModel = new AbstractTableModel() {
public int getColumnCount() { return names.length; }
public int getRowCount() { return data.length;}
public Object getValueAt(int row, int col) {return data[row][col];}
public String getColumnName(int column) {return names[column];}
public Class getColumnClass(int c) {return getValueAt(0, c).getClass();}
public boolean isCellEditable(int row, int col) {return getColumnClass(col) == String.class;}
public void setValueAt(Object aValue, int row, int column) { data[row][column] = aValue; }
};
// Create the table
JTable tableView = new JTable(dataModel);
// Show colors by rendering them in their own color.
DefaultTableCellRenderer colorRenderer = new DefaultTableCellRenderer() {
public void setValue(Object value) {
if (value instanceof Color) {
Color c = (Color)value;
setForeground(c);
setText(c.getRed() + ", " + c.getGreen() + ", " + c.getBlue());
}
}
};
colorRenderer.setHorizontalAlignment(JLabel.RIGHT);
//tableView.getColumn("Favorite Color").setCellRenderer(colorRenderer);
Enumeration columns = tableView.getColumnModel().getColumns();
while(columns.hasMoreElements())
{
((TableColumn)columns.nextElement()).setMinWidth(200);
}
tableView.setRowHeight(20);
JScrollPane scrollpane = JTable.createScrollPaneForTable(tableView);
return scrollpane;
}
// private ImageIcon loadIcon(String name, String description) {
// String path = "images/ImageClub/food/" + name;
//return JPanel.sharedInstance().loadImageIcon(path, description);
//}
}
(Review ID: 26070)
======================================================================
###@###.### 10/12/04 18:22 GMT