本文整理汇总了Java中javax.swing.table.DefaultTableCellRenderer.setToolTipText方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultTableCellRenderer.setToolTipText方法的具体用法?Java DefaultTableCellRenderer.setToolTipText怎么用?Java DefaultTableCellRenderer.setToolTipText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.table.DefaultTableCellRenderer
的用法示例。
在下文中一共展示了DefaultTableCellRenderer.setToolTipText方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUpSportColumn
import javax.swing.table.DefaultTableCellRenderer; //导入方法依赖的package包/类
public void setUpSportColumn(JTable table, TableColumn sportColumn) {
// Set up the editor for the sport cells.
JComboBox comboBox = new JComboBox();
comboBox.addItem("Snowboarding");
comboBox.addItem("Rowing");
comboBox.addItem("Knitting");
comboBox.addItem("Speed reading");
comboBox.addItem("Pool");
comboBox.addItem("None of the above");
sportColumn.setCellEditor(new DefaultCellEditor(comboBox));
// Set up tool tips for the sport cells.
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
renderer.setToolTipText("Click for combo box");
sportColumn.setCellRenderer(renderer);
}
示例2: setUpSportColumn
import javax.swing.table.DefaultTableCellRenderer; //导入方法依赖的package包/类
public void setUpSportColumn(JTable table,
TableColumn sportColumn) {
//Set up the editor for the sport cells.
JComboBox comboBox = new JComboBox();
comboBox.addItem("Snowboarding");
comboBox.addItem("Rowing");
comboBox.addItem("Knitting");
comboBox.addItem("Speed reading");
comboBox.addItem("Pool");
comboBox.addItem("None of the above");
sportColumn.setCellEditor(new DefaultCellEditor(comboBox));
//Set up tool tips for the sport cells.
DefaultTableCellRenderer renderer =
new DefaultTableCellRenderer();
renderer.setToolTipText("Click for combo box");
sportColumn.setCellRenderer(renderer);
}
示例3: testColumnToolTip
import javax.swing.table.DefaultTableCellRenderer; //导入方法依赖的package包/类
/**
* test doc'ed xheader.getToolTipText(MouseEvent) behaviour.
*
*/
@Test
public void testColumnToolTip() {
JXTable table = new JXTable(10, 2);
TableColumnExt columnExt = table.getColumnExt(0);
JXTableHeader tableHeader = (JXTableHeader) table.getTableHeader();
MouseEvent event = new MouseEvent(tableHeader, 0,
0, 0, 40, 5, 0, false);
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
String rendererToolTip = "rendererToolTip";
renderer.setToolTipText(rendererToolTip);
columnExt.setHeaderRenderer(renderer);
assertEquals(rendererToolTip, tableHeader.getToolTipText(event));
String columnToolTip = "columnToolTip";
columnExt.setToolTipText(columnToolTip);
assertEquals(columnToolTip, tableHeader.getToolTipText(event));
}
示例4: setupColumns
import javax.swing.table.DefaultTableCellRenderer; //导入方法依赖的package包/类
public static void setupColumns(JTable table) {
for (int i = 0; i < table.getColumnCount(); i++) {
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
TableColumn column = table.getColumnModel().getColumn(i);
Class columnClass = table.getColumnClass(i);
String columnName = table.getColumnName(i);
renderer.setToolTipText(columnName);
if (columnClass.getSuperclass().equals(Number.class)) {
renderer.setHorizontalAlignment(DefaultTableCellRenderer.RIGHT);
}
if (table.isEnabled()) {
if (columnName.equals("Currency")) {
//addComboCell(column, Product.CURRENCIES);
} else if (columnName.equals("Holidays")) {
//column.setCellEditor(new FileChooserCellEditor());
}
}
column.setCellRenderer(renderer);
}
}
示例5: getTableCellRendererComponent
import javax.swing.table.DefaultTableCellRenderer; //导入方法依赖的package包/类
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row, int col) {
final DefaultTableCellRenderer c = (DefaultTableCellRenderer) super.getTableCellRendererComponent(table, value,
isSelected, hasFocus, row, col);
final BasicNode node = (BasicNode) tree.getPathForRow(row)
.getLastPathComponent();
c.setEnabled(!node.isSkip());
if (node instanceof PieceNode) {
final String image = ((PieceNode) node).getImageName();
final String i = "<html><img src=\"file:/"+loadDirectory.getAbsolutePath()+"/"+image+"\"></html>";
c.setToolTipText(i);
}
return c;
}
示例6: getCellRenderer
import javax.swing.table.DefaultTableCellRenderer; //导入方法依赖的package包/类
/**
* This method sets read write rows to be blue, and other rows to be their
* default rendered colour.
*/
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
DefaultTableCellRenderer tcr =
(DefaultTableCellRenderer) super.getCellRenderer(row,column);
tcr.setToolTipText(getToolTip(row,column));
if (defaultColor == null) {
defaultColor = tcr.getForeground();
editableColor = Color.blue;
errorColor = Color.red;
// this sometimes happens for some reason
if (defaultColor == null) {
return tcr;
}
}
if (column != VALUE_COLUMN) {
tcr.setForeground(defaultColor);
return tcr;
}
if (isCellError(row,column)) {
tcr.setForeground(errorColor);
} else if (isCellEditable(row, column)) {
tcr.setForeground(editableColor);
} else {
tcr.setForeground(defaultColor);
}
return tcr;
}
示例7: addTextAreaToColumn
import javax.swing.table.DefaultTableCellRenderer; //导入方法依赖的package包/类
private void addTextAreaToColumn() {
//Create the ComboBox and add the line blocks to it
JTextField textArea = new JTextField();
//Add a listener to the ComboBox, add stop when state changes
textArea.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
int row = table.getSelectedRow();
String timeToDwell = textArea.getText();
if(SimTime.isValid(timeToDwell) && row>=0) {
schedule.addStop(row, new SimTime(timeToDwell));
fireScheduleChanged();
}
}
});
//Put the TextArea into the JTable cell
DefaultCellEditor textAreaEditor = new DefaultCellEditor(textArea);
this.getColumnModel().getColumn(1).setCellEditor(textAreaEditor);
//Add a tooltip
DefaultTableCellRenderer textAreaRenderer = new DefaultTableCellRenderer();
textAreaRenderer.setToolTipText("Type time to spend at the station");
this.getColumnModel().getColumn(1).setCellRenderer(textAreaRenderer);
}
示例8: initComp
import javax.swing.table.DefaultTableCellRenderer; //导入方法依赖的package包/类
private void initComp() {
schemaTable.getModel().addTableModelListener(this);
schemaTable.getTableHeader().setReorderingAllowed( false );
startString = getStartString();
//set key listener to delete rows when user presses del key
schemaTable.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent evt) {
tableKeyPressed(evt);
}
});
//add the initial row
addRow(startString);
//set width
TableColumn column = null;
for (int i = 0; i < 4; i++) {
column = schemaTable.getColumnModel().getColumn(i);
if (i == PRIMARY_COL) {
column.setPreferredWidth(40);
} else if(i ==SCHEMA_COL) {
column.setPreferredWidth(250);
} else {
column.setPreferredWidth(80);
}
}
//set renderer and editor for the first column
schemaTable.getColumnModel().getColumn(PRIMARY_COL).setCellRenderer(new RadioColumnRenderer());
schemaTable.getColumnModel().getColumn(PRIMARY_COL).setCellEditor(new RadioColumnEditor());
//set up rendere/editor for the combo box column
TableColumn rootColumn = schemaTable.getColumnModel().getColumn(ROOT_COL);
rootColumn.setCellEditor(new ComboBoxColumnEditor());
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
renderer.setToolTipText(NbBundle.getMessage(SchemaPanel.class, "TIP_COMBO_COL"));
rootColumn.setCellRenderer(renderer);
int height = schemaTable.getRowHeight();
// Determine highest cell in the row
for (int c=0; c<schemaTable.getColumnCount(); c++) {
TableCellRenderer r = schemaTable.getCellRenderer(0, c);
Component comp = schemaTable.prepareRenderer(r, 0, c);
int h = comp.getPreferredSize().height;
height = Math.max(height, h);
}
schemaTable.setRowHeight(height);
}
示例9: addComboBoxToColumn
import javax.swing.table.DefaultTableCellRenderer; //导入方法依赖的package包/类
/**
* Adds a combo box to the stops column for users to specify a stop
*/
private void addComboBoxToColumn() {
//Create the ComboBox and add the line blocks to it
JComboBox<String> blockCB = new JComboBox<String>();
blockCB.addItem("");
blockCB.addItem("-REMOVE-");
for(Block block : schedule.line.blocks) {
blockCB.addItem(block.toString());
}
//Add a listener to the ComboBox, add stop when state changes
blockCB.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
int row = table.getSelectedRow();
String blockText = (String)blockCB.getSelectedItem();
//Sometimes this is accidentally triggered so check the row
if(row==-1) {
return;
}
// CASE : -REMOVE-, remove the row
if(blockText.equals("-REMOVE-")) {
//Make sure the last row is not being removed
if(row<schedule.stops.size()) {
schedule.removeStop(row);
}
if(schedule.train!=null && schedule.stops.size()==0) {
schedule.addStop(0, schedule.line.yardIn);
}
//If no rows exist, add one for future stop additions
if(schedule.stops.size()==0) {
addBlankRow();
}
}
else if(!blockText.equals("")){
//Match the first number (single or multi-digit)
Matcher m = Pattern.compile("\\d+").matcher(blockText);
m.find();
int blockNum = Integer.valueOf(m.group());
if(blockNum!=-1) {
schedule.addStop(row, blockNum-1);
}
}
fireScheduleChanged();
}
}
});
//Put the ComboBox into the JTable cell
DefaultCellEditor editor = new DefaultCellEditor(blockCB);
this.getColumnModel().getColumn(0).setCellEditor(editor);
//Add a tooltip
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
renderer.setToolTipText("Click for combo box");
this.getColumnModel().getColumn(0).setCellRenderer(renderer);
}