在下面的示例中,我有一张桌子。如果将鼠标悬停在表格标题列边缘上,光标将变为调整大小光标符号。但是,如果您取消注释下面的行以将玻璃窗格设置为可见,则光标不再更改 - 但您仍然可以调整列的大小并以其他方式与表格交互(例如,选择表格单元格等)。
有没有办法在使用玻璃窗格时保持相同的鼠标光标行为?
我需要一个适用于 Java 6 的解决方案。
public class Test extends JPanel
{
public Test()
{
super(new GridLayout(1, 0));
String[] columnNames = { "First Name", "Last Name", "Sport", "# of Years", "Vegetarian" };
Object[][] data = { { "Kathy", "Smith", "Snowboarding", new Integer(5), new Boolean(false) },
{ "John", "Doe", "Rowing", new Integer(3), new Boolean(true) }, { "Sue", "Black", "Knitting", new Integer(2), new Boolean(false) },
{ "Jane", "White", "Speed reading", new Integer(20), new Boolean(true) }, { "Joe", "Brown", "Pool", new Integer(10), new Boolean(false) } };
final JTable table = new JTable(data, columnNames);
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
table.setFillsViewportHeight(true);
JScrollPane scrollPane = new JScrollPane(table);
add(scrollPane);
}
private static void createAndShowGUI()
{
JFrame frame = new JFrame("SimpleTableDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JPanel glass = (JPanel)frame.getGlassPane();
//glass.setVisible(true);
Test newContentPane = new Test();
newContentPane.setOpaque(true);
frame.setContentPane(newContentPane);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args)
{
javax.swing.SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
createAndShowGUI();
}
});
}
}