JScrollPane 不工作 我使用了 JForm Layout
JScrollPane is not working I used JForm Layout
JScrollPane 不工作。我在其中创建了一个面板,我添加了 JForm Layout。然后我添加标签和一个动态面板添加 JScrollPane,我在其中添加 table.
问题是这个 JScrollPane 不能正常工作。它没有显示垂直和水平条,它只是像一个带有 table 数据的常量面板一样反应。
public LedgerPanel_UI() {
setLayout(new FormLayout(new ColumnSpec[] {
FormSpecs.RELATED_GAP_COLSPEC,
ColumnSpec.decode("244dlu"),
FormSpecs.RELATED_GAP_COLSPEC,
ColumnSpec.decode("250dlu"),},
new RowSpec[] {
FormSpecs.RELATED_GAP_ROWSPEC,
RowSpec.decode("20dlu"),
FormSpecs.RELATED_GAP_ROWSPEC,
RowSpec.decode("fill:207dlu"),
FormSpecs.RELATED_GAP_ROWSPEC,
RowSpec.decode("fill:179dlu"),}));
style = new Style();
TableModel_Ledgers model = new TableModel_Ledgers();
JTable table = new JTable(model);
model.setColumnSize(table);
style.style_Table(table, table.getTableHeader(), false);
//scrollPane.getViewport().setPreferredSize(this.getPreferredSize());
model.setData();
model.fireTableDataChanged();
JLabel lblNewLabel = new JLabel("Add New Customer");
JScrollPane scrollPane = new JScrollPane();
//scrollPane = style.style_JScrollPane(scrollPane, table);
scrollPane.setViewportView(table);
add(new AddNewLedgerAccountp_UI().init_UI(), "4, 4");
add(lblNewLabel, "4, 2, center, fill");
add(scrollPane, "2, 4, 1, 3, fill, fill");
}
你应该试试这个。这应该始终显示标尺。
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
经过一番努力,这对我有用。table.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );
你可以试试这个:
JTable table = new JTable(model);
JScrollPane scrollpane= new JScrollPane(table);
add(new AddNewLedgerAccountp_UI().init_UI(), "4, 4");
...
它对我的 JTextArea 很有效。我不知道它是否适用于 JTable 或您的布局。
编辑:我也可以使用 JTable。
JScrollPane 不工作。我在其中创建了一个面板,我添加了 JForm Layout。然后我添加标签和一个动态面板添加 JScrollPane,我在其中添加 table.
问题是这个 JScrollPane 不能正常工作。它没有显示垂直和水平条,它只是像一个带有 table 数据的常量面板一样反应。
public LedgerPanel_UI() {
setLayout(new FormLayout(new ColumnSpec[] {
FormSpecs.RELATED_GAP_COLSPEC,
ColumnSpec.decode("244dlu"),
FormSpecs.RELATED_GAP_COLSPEC,
ColumnSpec.decode("250dlu"),},
new RowSpec[] {
FormSpecs.RELATED_GAP_ROWSPEC,
RowSpec.decode("20dlu"),
FormSpecs.RELATED_GAP_ROWSPEC,
RowSpec.decode("fill:207dlu"),
FormSpecs.RELATED_GAP_ROWSPEC,
RowSpec.decode("fill:179dlu"),}));
style = new Style();
TableModel_Ledgers model = new TableModel_Ledgers();
JTable table = new JTable(model);
model.setColumnSize(table);
style.style_Table(table, table.getTableHeader(), false);
//scrollPane.getViewport().setPreferredSize(this.getPreferredSize());
model.setData();
model.fireTableDataChanged();
JLabel lblNewLabel = new JLabel("Add New Customer");
JScrollPane scrollPane = new JScrollPane();
//scrollPane = style.style_JScrollPane(scrollPane, table);
scrollPane.setViewportView(table);
add(new AddNewLedgerAccountp_UI().init_UI(), "4, 4");
add(lblNewLabel, "4, 2, center, fill");
add(scrollPane, "2, 4, 1, 3, fill, fill");
}
你应该试试这个。这应该始终显示标尺。
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
经过一番努力,这对我有用。table.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );
你可以试试这个:
JTable table = new JTable(model);
JScrollPane scrollpane= new JScrollPane(table);
add(new AddNewLedgerAccountp_UI().init_UI(), "4, 4");
...
它对我的 JTextArea 很有效。我不知道它是否适用于 JTable 或您的布局。
编辑:我也可以使用 JTable。