本文整理汇总了Java中javax.swing.JTable.setPreferredScrollableViewportSize方法的典型用法代码示例。如果您正苦于以下问题:Java JTable.setPreferredScrollableViewportSize方法的具体用法?Java JTable.setPreferredScrollableViewportSize怎么用?Java JTable.setPreferredScrollableViewportSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JTable
的用法示例。
在下文中一共展示了JTable.setPreferredScrollableViewportSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createConstraintsTable
import javax.swing.JTable; //导入方法依赖的package包/类
public JTable createConstraintsTable(boolean rebuild) {
JTable table = new JTable(new VRPTableModel(rebuild));
table.setPreferredScrollableViewportSize(new Dimension(60, 60));
table.setAutoscrolls(true);
table.setAutoCreateColumnsFromModel(true);
table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
table.setMaximumSize(new Dimension(60, 60));
table.setBackground(Color.LIGHT_GRAY);
table.setBorder(BorderFactory.createCompoundBorder());
table.setForeground(Color.BLACK);
table.setShowGrid(true);
return table;
}
示例2: TablePrintDemo
import javax.swing.JTable; //导入方法依赖的package包/类
public TablePrintDemo() {
super();
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
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);
// Add a print button.
JButton printButton = new JButton("Print");
printButton.setAlignmentX(Component.CENTER_ALIGNMENT);
printButton.addActionListener(this);
add(printButton);
}
示例3: TableFTFEditDemo
import javax.swing.JTable; //导入方法依赖的package包/类
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);
}
示例4: TableSorterDemo
import javax.swing.JTable; //导入方法依赖的package包/类
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);
}
示例5: TableDialogEditDemo
import javax.swing.JTable; //导入方法依赖的package包/类
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);
}
示例6: TableRenderDemo
import javax.swing.JTable; //导入方法依赖的package包/类
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);
}
示例7: runTest
import javax.swing.JTable; //导入方法依赖的package包/类
private static void runTest() {
JDialog dialog = Util
.createModalDialogWithPassFailButtons("Empty header showing \"...\"");
String[] columnNames = {"", "", "", "", "Testing"};
String[][] data = {{"1", "2", "3", "4", "5"}};
JTable table = new JTable(data, columnNames);
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
int tableCellWidth = renderer.getFontMetrics(renderer.getFont())
.stringWidth("test");
table.setPreferredScrollableViewportSize(new Dimension(
5 * tableCellWidth, 50));
JPanel p = new JPanel();
p.add(new JScrollPane(table));
dialog.add(p, BorderLayout.NORTH);
JTextArea area = new JTextArea();
String txt = "\nInstructions:\n\n";
txt += "Only the last column header should show \"...\".";
area.setText(txt);
dialog.add(new JScrollPane(area), BorderLayout.CENTER);
dialog.pack();
dialog.setVisible(true);
}
示例8: SimpleTableDemo
import javax.swing.JTable; //导入方法依赖的package包/类
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);
}
示例9: TableDemo
import javax.swing.JTable; //导入方法依赖的package包/类
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);
}
示例10: TableSortDemo
import javax.swing.JTable; //导入方法依赖的package包/类
public TableSortDemo() {
super(new GridLayout(1, 0));
JTable table = new JTable(new MyTableModel());
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
table.setFillsViewportHeight(true);
table.setAutoCreateRowSorter(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);
}
示例11: GraphicTable
import javax.swing.JTable; //导入方法依赖的package包/类
public GraphicTable() {
graphicTable = new JTable();
graphicTable.setEnabled(false);
graphicTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
graphicTable.setMinimumSize(graphicTable.getPreferredScrollableViewportSize());
graphicTable.setPreferredScrollableViewportSize(graphicTable.getPreferredSize());
graphicTable.setFillsViewportHeight(true);
graphicTable.getTableHeader().setReorderingAllowed(false);
graphicTable.setColumnSelectionAllowed(true);
graphicTable.setRowSelectionAllowed(true);
graphicTable.setRowSelectionAllowed(true);
//(ListSelectionModel.SINGLE_SELECTION);
}
示例12: mouseDragged
import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public void mouseDragged(MouseEvent e)
{
int width = columnWidth - pressedX + e.getX();
column.setPreferredWidth( width );
JTableHeader header = (JTableHeader)e.getComponent();
JTable table = header.getTable();
table.setPreferredScrollableViewportSize(table.getPreferredSize());
JScrollPane scrollPane = (JScrollPane)table.getParent().getParent();
scrollPane.revalidate();
}
示例13: createContent
import javax.swing.JTable; //导入方法依赖的package包/类
@Override
protected JPanel createContent() {
JPanel content = new JPanel();
GroupLayout layout = new GroupLayout(content);
content.setLayout(layout);
layout.setAutoCreateGaps(true);
layout.setAutoCreateContainerGaps(true);
// parameters panel
hhTable = new JTable();
hhTable.setAutoscrolls(true);
JScrollPane resScrollPane = new JScrollPane(hhTable);
resScrollPane
.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
resScrollPane
.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
hhTable.setFillsViewportHeight(true);
hhTable.setPreferredScrollableViewportSize(new Dimension(400, 100));
hhTableModel = new MyTableModel();
hhTable.setModel(hhTableModel);
hhTable.setDefaultRenderer(Class.class, new MyClassTableCellRenderer());
hhTable.setDefaultEditor(Double.class, new MyDoubleTableCellEditor());
hhTableModel.addColumn("Select");
hhTableModel.addColumn("Hidden Hop Mapping");
hhTableModel.addColumn("Factor");
JPanel hhPanel = new JPanel();
hhPanel.setBorder(BorderFactory.createTitledBorder("Hidden Hops"));
hhPanel.add(resScrollPane);
// create the content for the hh panel
for (Class<?> hh : getAllHhs()) {
try {
hh.getDeclaredField(new String("factor"));
// add a row to the factor table.
hhTableModel
.addRow(new Object[] { false, hh, new Double(0.0) });
} catch (NoSuchFieldException ex) {
}
}
// add the panels
layout.setHorizontalGroup(layout.createParallelGroup().addComponent(
hhPanel));
layout.setVerticalGroup(layout.createSequentialGroup().addComponent(
hhPanel));
return content;
}
示例14: SymbolPanel
import javax.swing.JTable; //导入方法依赖的package包/类
public SymbolPanel() {
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
mainPanel = new JPanel();
mainPanel.setBorder(BorderFactory.createLineBorder(Color.black));
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
Box box = Box.createHorizontalBox();
box.add(new JLabel("Items"));
mainPanel.add(box);
model = new SymbolTableModel();
table = new JTable(model);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
if (getValueList() != null && getValueList().size() > 0) {
table.getSelectionModel().setSelectionInterval(0, 0);
}
ListSelectionModel rowSM = table.getSelectionModel();
rowSM.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting()) return;
ListSelectionModel lsm = (ListSelectionModel) e.getSource();
if (lsm.isSelectionEmpty()) {
showItem(NO_CURRENT_ITEM);
}
else {
int selectedRow = lsm.getMinSelectionIndex();
showItem(selectedRow);
}
}
});
scrollPane = new ScrollPane(table);
table.setPreferredScrollableViewportSize(new Dimension(300, 100));
mainPanel.add(scrollPane);
detailPanel = new JPanel();
mainPanel.add(new ScrollPane(detailPanel));
add(mainPanel);
showItem(0);
}
示例15: SimpleTableDemo
import javax.swing.JTable; //导入方法依赖的package包/类
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);
}