下面列出了javax.swing.JTable#setPreferredScrollableViewportSize ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public TableFTFEditDemo() {
super(new GridLayout(1, 0));
JTable table = new JTable(new MyTableModel());
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
table.setFillsViewportHeight(true);
// Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
// Set up stricter input validation for the integer column.
table.setDefaultEditor(Integer.class, new IntegerEditor(0, 100));
// If we didn't want this editor to be used for other
// Integer columns, we'd do this:
// table.getColumnModel().getColumn(3).setCellEditor(
// new IntegerEditor(0, 100));
// Add the scroll pane to this panel.
add(scrollPane);
}
public TableSorterDemo() {
super(new GridLayout(1, 0));
TableSorter sorter = new TableSorter(new MyTableModel()); // ADDED THIS
// JTable table = new JTable(new MyTableModel()); //OLD
JTable table = new JTable(sorter); // NEW
sorter.setTableHeader(table.getTableHeader()); // ADDED THIS
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
// Set up tool tips for column headers.
table.getTableHeader().setToolTipText("Click to specify sorting; Control-Click to specify secondary sorting");
// Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
// Add the scroll pane to this panel.
add(scrollPane);
}
public TableDialogEditDemo() {
super(new GridLayout(1, 0));
JTable table = new JTable(new MyTableModel());
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
table.setFillsViewportHeight(true);
// Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
// Set up renderer and editor for the Favorite Color column.
table.setDefaultRenderer(Color.class, new ColorRenderer(true));
table.setDefaultEditor(Color.class, new ColorEditor());
// Add the scroll pane to this panel.
add(scrollPane);
}
public TableRenderDemo() {
super(new GridLayout(1, 0));
JTable table = new JTable(new MyTableModel());
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
table.setFillsViewportHeight(true);
// Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
// Set up column sizes.
initColumnSizes(table);
// Fiddle with the Sport column's cell editors/renderers.
setUpSportColumn(table, table.getColumnModel().getColumn(2));
// Add the scroll pane to this panel.
add(scrollPane);
}
public TableRenderDemo() {
super(new GridLayout(1,0));
JTable table = new JTable(new MyTableModel());
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
table.setFillsViewportHeight(true);
//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
//Set up column sizes.
initColumnSizes(table);
//Fiddle with the Sport column's cell editors/renderers.
setUpSportColumn(table, table.getColumnModel().getColumn(2));
//Add the scroll pane to this panel.
add(scrollPane);
}
public GfxdTop() {
super(new GridLayout(1,0));
tmodel = new StatementTableModel();
queryStats = new ClusterStatistics();
JTable table = new JTable(tmodel);
table.setPreferredScrollableViewportSize(new Dimension(500, 300));
table.setDefaultRenderer(Double.class, new DoubleRenderer());
table.setIntercellSpacing(new Dimension(6,3));
table.setRowHeight(table.getRowHeight() + 4);
JScrollPane scrollPane = new JScrollPane(table);
add(scrollPane);
}
/**
* Fixe la taille exacte d'une JTable à celle nécessaire pour afficher les données.
* @param table JTable
*/
public static void adjustTableHeight(final JTable table) {
table.setPreferredScrollableViewportSize(
new Dimension(-1, table.getPreferredSize().height));
// on utilise invokeLater pour configurer le scrollPane car lors de l'exécution ce cette méthode
// la table n'est pas encore dans son scrollPane parent
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
final JScrollPane scrollPane = MSwingUtilities.getAncestorOfClass(JScrollPane.class,
table);
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
// Puisqu'il n'y a pas d'ascenceur sur ce scrollPane,
// il est inutile que la mollette de souris serve à bouger cet ascenseur,
// mais il est très utile en revanche que ce scrollPane ne bloque pas l'utilisation
// de la mollette de souris pour le scrollPane global de l'onglet principal.
// On commence par enlever le listener au cas où la méthode soit appelée deux fois sur la même table.
scrollPane.removeMouseWheelListener(DELEGATE_TO_PARENT_MOUSE_WHEEL_LISTENER);
scrollPane.addMouseWheelListener(DELEGATE_TO_PARENT_MOUSE_WHEEL_LISTENER);
}
});
}
/**
* Initialize JTable that contains namespaces
*/
private void initTable()
{
namespaces = new JTable(new FilterTableModel());
namespaces.removeColumn(namespaces.getColumn("#"));
namespaces.setFillsViewportHeight(true);
namespaces.setPreferredScrollableViewportSize(new Dimension(500, 70));
// Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(namespaces);
scrollPane.setBounds(70, 10, 300, 200);
this.add(scrollPane);
}
public void CreateEmployeeTable(EmployeeRepository employeeRepository)
throws ParserConfigurationException, SAXException, IOException {
ArrayList<Employee> employeeList = new ArrayList<>();
employeeList = employeeRepository.load();
if (employeeList.size() != 0) {
String[] columnNames = { "Name", "ID", "Salary", "Is dead" };
String[][] info = new String[employeeList.size()][4];
for (int row = 0; row < employeeList.size(); row++) {
info[row][0] = String.valueOf(employeeList.get(row).getName());
info[row][1] = String.valueOf(employeeList.get(row).getId());
info[row][2] = String.valueOf(employeeList.get(row).getSalary());
info[row][3] = String.valueOf(employeeList.get(row).getIsDead());
}
JTable employeeTable = new JTable(info, columnNames);
employeeTable.setPreferredScrollableViewportSize(new Dimension(Frames.WIDTH, Frames.HEIGHT));
employeeTable.setFillsViewportHeight(true);
getContentPane().add(new JScrollPane(employeeTable), BorderLayout.CENTER);
pack();
} else {
JOptionPane.showMessageDialog(contentPanel, "No employee to display.", "Warning",
JOptionPane.WARNING_MESSAGE);
}
}
public SimpleTableDemo() {
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);
if (DEBUG) {
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
printDebugData(table);
}
});
}
// Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
// Add the scroll pane to this panel.
add(scrollPane);
}
public TableDemo() {
super(new GridLayout(1, 0));
JTable table = new JTable(new MyTableModel());
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
table.setFillsViewportHeight(true);
// Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
// Add the scroll pane to this panel.
add(scrollPane);
}
public void CreateAnimalTable(AnimalRepository animalRepository)
throws ParserConfigurationException, SAXException, IOException {
ArrayList<Animal> animalList = new ArrayList<>();
animalList = animalRepository.load();
if (animalList.size() != 0) {
String[] columnNames = { "Name", "Danger %", "Maintenance Cost", "# of legs", "Taken care of" };
String[][] info = new String[animalList.size()][5];
for (int row = 0; row < animalList.size(); row++) {
info[row][0] = String.valueOf(animalList.get(row).getName());
info[row][1] = String.valueOf(animalList.get(row).getDangerPerc());
info[row][2] = String.valueOf(animalList.get(row).getMaintenanceCost());
info[row][3] = String.valueOf(animalList.get(row).getNrOfLegs());
info[row][4] = String.valueOf(animalList.get(row).getTakenCareOf());
}
JTable animalTable = new JTable(info, columnNames);
animalTable.setPreferredScrollableViewportSize(new Dimension(Frames.WIDTH, Frames.HEIGHT));
animalTable.setFillsViewportHeight(true);
getContentPane().add(new JScrollPane(animalTable), BorderLayout.CENTER);
pack();
} else {
JOptionPane.showMessageDialog(contentPanel, "No animal to display.", "Warning",
JOptionPane.WARNING_MESSAGE);
}
}
public ListEmployees(String title, ArrayList<Employee> employees) {
super(title);
this.employees = employees;
contentPanel.setLayout(new FlowLayout());
JPanel panel = new JPanel();
contentPanel.add(panel);
JPanel pan = new JPanel();
contentPanel.add(pan);
FlowLayout slPanel = new FlowLayout();
pan.setLayout(slPanel);
String[] columns1 = { "Function", "Name", "ID", "Salary" };
String[][] info1 = new String[employees.size()][columns1.length];
int i1 = 0;
for (Employee employee : employees) {
info1[i1][0] = employee.getClass().getSimpleName();
info1[i1][1] = employee.getName();
info1[i1][2] = String.valueOf(employee.getId());
info1[i1][3] = String.valueOf(employee.getSalary());
i1++;
}
JTable table1 = new JTable(info1, columns1);
table1.setPreferredScrollableViewportSize(new Dimension(500, 50));
table1.setFillsViewportHeight(true);
JScrollPane scrollPane1 = new JScrollPane(table1);
add(scrollPane1);
JPanel panel_2 = new JPanel();
contentPanel.add(panel_2);
setVisible(true);
}
public ElementsTableComponent() {
super(new BorderLayout());
elementsTableModel = new ElementsTableModel();
elementsTable = new JTable(elementsTableModel);
elementsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
elementsTable.setRowSelectionAllowed(true);
elementsTable.setColumnSelectionAllowed(false);
elementsTable.setDefaultRenderer(Object.class, new ComponentCellRenderer(smallFont));
elementsTable.getTableHeader().setReorderingAllowed(false);
elementsTable.getTableHeader().setResizingAllowed(false);
elementsTable.setPreferredScrollableViewportSize(new Dimension(200, 80));
JScrollPane elementsScroll = new JScrollPane(elementsTable);
add(elementsScroll, BorderLayout.CENTER);
// Add buttons
JPanel buttonsPanel = new JPanel();
BoxLayout buttonsPanelLayout = new BoxLayout(buttonsPanel, BoxLayout.Y_AXIS);
buttonsPanel.setLayout(buttonsPanelLayout);
addElementButton = GUIUtils.addButton(buttonsPanel, "Add", null, this);
removeElementButton = GUIUtils.addButton(buttonsPanel, "Remove", null, this);
add(buttonsPanel, BorderLayout.EAST);
this.setPreferredSize(new Dimension(300, 100));
}
public SimpleTableDemo(LazyReplicatedMap<String,StringBuilder> map) {
super();
this.map = map;
this.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
//final JTable table = new JTable(data, columnNames);
table = new JTable(dataModel);
table.setPreferredScrollableViewportSize(new Dimension(WIDTH, 150));
for ( int i=0; i<table.getColumnCount(); i++ ) {
TableColumn tm = table.getColumnModel().getColumn(i);
tm.setCellRenderer(new ColorRenderer());
}
if (DEBUG) {
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
printDebugData(table);
}
});
}
//setLayout(new GridLayout(5, 0));
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
//Add the scroll pane to this panel.
add(scrollPane);
//create a add value button
JPanel addpanel = new JPanel();
addpanel.setPreferredSize(new Dimension(WIDTH,30));
addpanel.add(createButton("Add","add"));
addpanel.add(txtAddKey);
addpanel.add(txtAddValue);
addpanel.setMaximumSize(new Dimension(WIDTH,30));
add(addpanel);
//create a remove value button
JPanel removepanel = new JPanel( );
removepanel.setPreferredSize(new Dimension(WIDTH,30));
removepanel.add(createButton("Remove","remove"));
removepanel.add(txtRemoveKey);
removepanel.setMaximumSize(new Dimension(WIDTH,30));
add(removepanel);
//create a change value button
JPanel changepanel = new JPanel( );
changepanel.add(createButton("Change","change"));
changepanel.add(txtChangeKey);
changepanel.add(txtChangeValue);
changepanel.setPreferredSize(new Dimension(WIDTH,30));
changepanel.setMaximumSize(new Dimension(WIDTH,30));
add(changepanel);
//create sync button
JPanel syncpanel = new JPanel( );
syncpanel.add(createButton("Synchronize","sync"));
syncpanel.add(createButton("Replicate","replicate"));
syncpanel.add(createButton("Random","random"));
syncpanel.setPreferredSize(new Dimension(WIDTH,30));
syncpanel.setMaximumSize(new Dimension(WIDTH,30));
add(syncpanel);
}
public GanttChart(SystemState state) {
this.state = state;
scale = INITIAL_SCALE;
jobs = new ArrayList<Job>();
jobmap = new HashMap<String, Job>();
header = new JTable() {
public Dimension getPreferredSize() {
Dimension d = super.getPreferredSize();
return new Dimension(50, d.height);
}
};
header.setModel(hmodel = new HeaderModel());
header.setShowHorizontalLines(true);
header.setPreferredScrollableViewportSize(new Dimension(100, 10));
header.setDefaultRenderer(Job.class, new JobNameRenderer());
table = new JTable();
table.setDoubleBuffered(true);
table.setModel(cmodel = new ChartModel());
table.setShowHorizontalLines(true);
table.setDefaultRenderer(Job.class, new JobRenderer());
JPanel jp = new JPanel();
jp.setLayout(new BorderLayout());
jp.add(table, BorderLayout.CENTER);
csp = new JScrollPane(jp);
csp.setColumnHeaderView(new Tickmarks());
csp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
csp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
csp.setRowHeaderView(header);
csp.getVerticalScrollBar().getModel().addChangeListener(this);
hsb = new JScrollBar(JScrollBar.HORIZONTAL);
hsb.setVisible(true);
hsb.getModel().addChangeListener(this);
setLayout(new BorderLayout());
add(csp, BorderLayout.CENTER);
add(createTools(), BorderLayout.NORTH);
add(hsb, BorderLayout.SOUTH);
state.schedule(new TimerTask() {
@Override
public void run() {
GanttChart.this.actionPerformed(null);
}
}, 1000, 1000);
}
/**
* Creates a new TipsDialog.
*/
public KeyboardShortcutsDialog() {
super( "keyboardShortcuts.title", Icons.KEYBOARD );
final String CTRL = Language.getText( "keyboardShortcuts.key.ctrl" ) + '+';
final String SHIFT = Language.getText( "keyboardShortcuts.key.shift" ) + '+';
final String ALT = Language.getText( "keyboardShortcuts.key.alt" ) + '+';
final String NUMBER = Language.getText( "keyboardShortcuts.key.number" );
final String FUNCION_KEY = Language.getText( "keyboardShortcuts.key.functionKey" );
final JTable table = GuiUtils.createNonEditableTable();
table.setAutoCreateRowSorter( true );
( (DefaultTableModel) table.getModel() ).setDataVector( createData(
new String[][] {
{ "global",
"enableDisableReplayAutoSave" , CTRL + ALT + "R" },
{ null, "enableDisableApmAlert" , CTRL + ALT + "A" },
{ null, "startStopMousePrintRecording" , CTRL + ALT + "M" },
{ null, "switchToSc2gears" , CTRL + ALT + "T" },
{ null, "showHideLastGameInfoDialog" , CTRL + ALT + "I" },
{ null, "showHideApmDisplayDialog" , CTRL + ALT + "U" },
{ "general",
"openReplay" , CTRL + "O" },
{ null, "openLastReplay" , CTRL + SHIFT+ "O" },
{ null, "exit" , ALT + "X" },
{ null, "miscSettings" , CTRL + "P" },
{ null, "filterTableRows" , CTRL + "F" },
{ null, "filterOutTableRows" , CTRL + "T" },
{ null, "openTool" , CTRL + SHIFT + FUNCION_KEY },
{ null, "fullScreen" , "F11" },
{ null, "minimieToTray" , "F9" },
{ null, "tileAllWindows" , "F2" },
{ null, "cascadeAllWindows" , "F3" },
{ null, "tileVisibleWindows" , CTRL + "F2" },
{ null, "cascadeVisibleWindows" , CTRL + "F3" },
{ null, "visitHomePage" , CTRL + "F1" },
{ null, "showStartPage" , "F1" },
{ null, "closeInternalWindow" , CTRL + "F4" },
{ null, "restoreInternalWindowSize" , CTRL + "F5" },
{ null, "cycleThroughTabs" , CTRL + "TAB" },
{ null, "cycleThroughInternalWindows" , CTRL + "TAB" },
{ null, "cycleThroughInternalWindows" , CTRL + "F6" },
{ null, "switchNavTreeIntWindows" , "F6" },
{ null, "focusNavTreeIntWindowsSplitter", "F8" },
{ null, "windowContextMenu" , CTRL + "SPACE" },
{ null, "mainMenu" , "F10" },
{ null, "closeTab" , CTRL + "W" },
{ "startPage",
"refreshContent" , "F5" },
{ "replayAnalyzer",
"selectChart" , CTRL + NUMBER },
{ null, "openCloseOverlayChart" , CTRL + SHIFT + NUMBER },
{ null, "zoomIn" , CTRL + "I" },
{ null, "zoomOut" , CTRL + "U" },
{ null, "gridOnOff" , CTRL + "G" },
{ null, "openGridSettings" , CTRL + SHIFT + "G" },
{ null, "playPause" , CTRL + "W" },
{ null, "jumpBackward" , CTRL + "Q" },
{ null, "jumpForward" , CTRL + "E" },
{ null, "jumpToBeginning" , CTRL + SHIFT + "Q" },
{ null, "jumpToEnd" , CTRL + SHIFT + "E" },
{ null, "slowDown" , CTRL + "R" },
{ null, "speedUp" , CTRL + SHIFT + "R" },
{ null, "jumpToFrame" , CTRL + "J" },
{ null, "searchText" , CTRL + "S" },
{ null, "filterActions" , CTRL + "F" },
{ null, "filterOutActions" , CTRL + "T" },
{ "multiRepAnalysis",
"selectChart" , CTRL + NUMBER },
{ "onTopApmDisplay",
"increaseFontSize" , "+" },
{ null, "decreaseFontSize" , "-" }
} ), new Object[] { Language.getText( "keyboardShortcuts.table.header.context" ), Language.getText( "keyboardShortcuts.table.header.function" ), Language.getText( "keyboardShortcuts.table.header.shortcut" ), } );
table.setPreferredScrollableViewportSize( new Dimension( 900, 500 ) );
GuiUtils.packTable( table );
final TableBox tableBox = new TableBox( table, getLayeredPane(), null );
tableBox.setBorder( BorderFactory.createEmptyBorder( 15, 15, 10, 15 ) );
getContentPane().add( tableBox, BorderLayout.CENTER );
final JPanel buttonsPanel = new JPanel();
buttonsPanel.setBorder( BorderFactory.createEmptyBorder( 0, 15, 10, 15 ) );
final JButton closeButton = createCloseButton( "button.close" );
buttonsPanel.add( closeButton );
getContentPane().add( buttonsPanel, BorderLayout.SOUTH );
packAndShow( closeButton, false );
}
/**
* Constructor
*
* @param scienceWindow the science window.
*/
FinishedStudyListPanel(ScienceWindow scienceWindow) {
// Use JPanel constructor.
super();
this.scienceWindow = scienceWindow;
setLayout(new BorderLayout());
JLabel titleLabel = new JLabel(Msg.getString("FinishedStudyListPanel.finishedScientificStudies"), //$NON-NLS-1$
JLabel.CENTER);
add(titleLabel, BorderLayout.NORTH);
// Create list scroll pane.
listScrollPane = new JScrollPane();
listScrollPane.setBorder(new MarsPanelBorder());
listScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
add(listScrollPane, BorderLayout.CENTER);
// Create study table model.
studyTableModel = new StudyTableModel();
// Create study table.
studyTable = new JTable(studyTableModel);
studyTable.setPreferredScrollableViewportSize(new Dimension(500, 200));
studyTable.setCellSelectionEnabled(false);
studyTable.setRowSelectionAllowed(true);
studyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
studyTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent event) {
if (event.getValueIsAdjusting()) {
int row = studyTable.getSelectedRow();
if (row >= 0) {
ScientificStudy selectedStudy = studyTableModel.getStudy(row);
if (selectedStudy != null)
setSelectedScientificStudy(selectedStudy);
}
}
}
});
studyTable.getColumnModel().getColumn(0).setPreferredWidth(40);
studyTable.getColumnModel().getColumn(1).setPreferredWidth(7);
studyTable.getColumnModel().getColumn(2).setPreferredWidth(80);
studyTable.getColumnModel().getColumn(3).setPreferredWidth(80);
studyTable.getColumnModel().getColumn(3).setPreferredWidth(80);
studyTable.setAutoCreateRowSorter(true);
TableStyle.setTableStyle(studyTable);
listScrollPane.setViewportView(studyTable);
}
protected void initComponents() {
setLayout(new BorderLayout());
controlPanel = createControlPanel();
add(controlPanel, BorderLayout.NORTH);
//<snip>Create JTable
oscarTable = new JTable(oscarModel);
//</snip>
//</snip>Set JTable display properties
oscarTable.setColumnModel(createColumnModel());
oscarTable.setAutoCreateRowSorter(true);
oscarTable.setRowHeight(26);
oscarTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
oscarTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
oscarTable.setIntercellSpacing(new Dimension(0, 0));
//</snip>
//<snip>Initialize preferred size for table's viewable area
Dimension viewSize = new Dimension();
viewSize.width = oscarTable.getColumnModel().getTotalColumnWidth();
viewSize.height = 10 * oscarTable.getRowHeight();
oscarTable.setPreferredScrollableViewportSize(viewSize);
//</snip>
//<snip>Customize height and alignment of table header
JTableHeader header = oscarTable.getTableHeader();
header.setPreferredSize(new Dimension(30, 26));
TableCellRenderer headerRenderer = header.getDefaultRenderer();
if (headerRenderer instanceof JLabel) {
((JLabel) headerRenderer).setHorizontalAlignment(JLabel.CENTER);
}
//</snip>
LuckScrollPane scrollpane = new LuckScrollPane(oscarTable);
dataPanel = new Stacker(scrollpane);
add(dataPanel, BorderLayout.CENTER);
add(createStatusBar(), BorderLayout.SOUTH);
}
@Override
public void actionPerformed(ActionEvent e)
{
EquipmentSetFacade equipSet = character.getEquipmentSetRef().get();
List<EquipNode> paths = getSelectedEquipmentSetNodes();
if (!paths.isEmpty())
{
Object[][] data = new Object[paths.size()][3];
for (int i = 0; i < paths.size(); i++)
{
EquipNode path = paths.get(i);
data[i][0] = path.getEquipment();
data[i][1] = equipSet.getQuantity(path);
}
Object[] columns = {LanguageBundle.getString("in_equipItem"), //$NON-NLS-1$
LanguageBundle.getString("in_equipQuantityAbbrev"), //$NON-NLS-1$
};
DefaultTableModel tableModel = new DefaultTableModel(data, columns)
{
@Override
public Class<?> getColumnClass(int columnIndex)
{
if (columnIndex == 1)
{
return Integer.class;
}
return Object.class;
}
@Override
public boolean isCellEditable(int row, int column)
{
return column != 0;
}
};
JTable table = new JTable(tableModel);
table.setFocusable(false);
table.setCellSelectionEnabled(false);
table.setDefaultRenderer(Integer.class, new TableCellUtilities.SpinnerRenderer());
table.setDefaultEditor(Integer.class, new SpinnerEditor(equipSet.getEquippedItems()));
table.setRowHeight(22);
table.getColumnModel().getColumn(0).setPreferredWidth(140);
table.getColumnModel().getColumn(1).setPreferredWidth(50);
table.setPreferredScrollableViewportSize(table.getPreferredSize());
JTableHeader header = table.getTableHeader();
header.setReorderingAllowed(false);
JScrollPane pane = EquipmentModels.prepareScrollPane(table);
JPanel panel = new JPanel(new BorderLayout());
JLabel help = new JLabel(LanguageBundle.getString("in_equipSelectUnequipQty")); //$NON-NLS-1$
panel.add(help, BorderLayout.NORTH);
panel.add(pane, BorderLayout.CENTER);
int res = JOptionPane.showConfirmDialog(JOptionPane.getFrameForComponent(equipmentTable), panel,
LanguageBundle.getString("in_equipUnequipSel"), //$NON-NLS-1$
JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
if (res == JOptionPane.OK_OPTION)
{
for (int i = 0; i < paths.size(); i++)
{
equipSet.removeEquipment(paths.get(i), (Integer) tableModel.getValueAt(i, 1));
}
}
}
}