在 Java 6u16 上使用 Swing,WinXP SP3
大家好。对于以下案例,我需要一些帮助。基本上我在 JScrollPane 中使用 JTable,在 scrollPane 上我应用从右到左的组件方向。我得到的最终结果是表格确实附在右侧,但当滚动窗格大于表格宽度时,标题放在左侧。这只发生在自定义表头和表列上的 AUTO_RESIZE_OFF 上(以获得水平滚动)。
第二个(相关)问题是拖动垂直网格线来调整列的大小 - 当表格列的行向右移动时,标题行向左移动。我有 2 个测试用例。第一个使用来自http://www.swebb99.f2s.com/GroupableHeader/的代码。这是用于对一些子列标题进行分组的表头的开源实现。请添加到 GroupableColumnExample.java 中的 main():
frame.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
第二个测试用例使用 JIDE (www.jidesoft.com) 实现嵌套表头,目的相同,结果相同。
import java.awt.ComponentOrientation;
import javax.swing.*;
import com.jidesoft.grid.JideTable;
public class TestCase {
public static void main(String[] args) {
JFrame frame = new JFrame("Demo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JideTable table = new JideTable(
new Object[][]{{"1", "2"}}, new String[]{"3", "4"});
//this line adds the custom header and the problem begins
table.setNestedTableHeader(true);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
frame.add(new JScrollPane(table));
//make frame bigger than needed to display the table
frame.setSize(200, 200);
frame.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
frame.setVisible(true);
}
}
请帮我解决这个问题,因为我没有通过谷歌找到任何东西,也无法自己解决问题。