我正在使用 jFileChooser 并且正在嘗試實作以下目標:
https://i.stack.imgur.com/O6MNj.png
我正在嘗試強制LIST視圖具有VERTICAL滾動條,或者我的第二個選項是從詳細資訊視圖中禁用大小和修改的列。
編輯:
有什么方法可以在 jFileChooser 中插入 JScrollBar?
uj5u.com熱心網友回復:
您可以訪問 JList 并更改串列的方向,如下所示:
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import java.util.List;
class FileChooserList
{
private static void createAndShowUI()
{
JFileChooser fileChooser = new JFileChooser(".");
// Change list orientation
JList list = SwingUtils.getDescendantsOfType(JList.class, fileChooser).get(0);
list.setLayoutOrientation( JList.VERTICAL );
fileChooser.showOpenDialog(null);
}
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
createAndShowUI();
}
});
}
}
上面的代碼需要Swing Utils類。
從詳細資訊視圖中禁用大小和修改的列
取決于您所說的“禁用”是什么意思。
您可以從表的視圖中洗掉這些列:
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import java.util.List;
class FileChooserDetails
{
private static void createAndShowUI()
{
JFileChooser fileChooser = new JFileChooser(".");
// Show the Details view of the file chooser
Action details = fileChooser.getActionMap().get("viewTypeDetails");
details.actionPerformed(null);
// Remove columns from view
JTable table = SwingUtils.getDescendantsOfType(JTable.class, fileChooser).get(0);
TableColumnModel tcm = table.getColumnModel();
tcm.removeColumn( tcm.getColumn(3) );
tcm.removeColumn( tcm.getColumn(1) );
fileChooser.showOpenDialog(null);
}
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
createAndShowUI();
}
});
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/516703.html
標籤:爪哇摇摆
