本文整理匯總了Java中javax.swing.table.DefaultTableCellRenderer類的典型用法代碼示例。如果您正苦於以下問題:Java DefaultTableCellRenderer類的具體用法?Java DefaultTableCellRenderer怎麽用?Java DefaultTableCellRenderer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DefaultTableCellRenderer類屬於javax.swing.table包,在下文中一共展示了DefaultTableCellRenderer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getValueAddedTaxPercentageRenderer
import javax.swing.table.DefaultTableCellRenderer; //導入依賴的package包/類
/**
* Returns a renderer that displays the value added tax percentage property of a piece of furniture.
*/
private TableCellRenderer getValueAddedTaxPercentageRenderer()
{
return new DefaultTableCellRenderer()
{
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column)
{
BigDecimal valueAddedTaxPercentage = value != null
? ((HomePieceOfFurniture) value).getValueAddedTaxPercentage() : null;
if (valueAddedTaxPercentage != null)
{
NumberFormat percentInstance = DecimalFormat.getPercentInstance();
percentInstance.setMinimumFractionDigits(valueAddedTaxPercentage.scale() - 2);
value = percentInstance.format(valueAddedTaxPercentage);
}
else
{
value = null;
}
setHorizontalAlignment(JLabel.RIGHT);
return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
}
};
}
示例2: TelaBuscarVeiculo
import javax.swing.table.DefaultTableCellRenderer; //導入依賴的package包/類
public TelaBuscarVeiculo() {
initComponents();
jtb_Veiculos.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
ButtonGroup group = new ButtonGroup();
group.add(jrb_Marca);
group.add(jrb_Modelo);
group.add(jrb_Ano);
group.add(jrb_MenorPreco);
group.add(jrb_MaiorPreco);
DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
centerRenderer.setHorizontalAlignment( JLabel.CENTER );
jtb_Veiculos.setDefaultRenderer(Object.class, centerRenderer);
}
示例3: atualizaTela
import javax.swing.table.DefaultTableCellRenderer; //導入依賴的package包/類
public void atualizaTela(){
meusVeiculos = new ArrayList<>();
DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
centerRenderer.setHorizontalAlignment( JLabel.CENTER );
jtb_Veiculos.setDefaultRenderer(Object.class, centerRenderer);
jtb_Veiculos.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
DefaultTableModel model = (DefaultTableModel)jtb_Veiculos.getModel();
model.setRowCount(0);
ArrayList<VendaVeiculo> aux = NegocioFacade.listaVeiculos();
Usuario logado = NegocioFacade.getUsuarioLogado();
for(VendaVeiculo a : aux){
if(a.getProprietario().getCpf().equals(logado.getCpf())){
model.addRow(new Object[]{ a.getVeiculo().getMarca(), a.getVeiculo().getModelo(),
a.getVeiculo().getCor(), a.getVeiculo().getAno(), a.getPreco()});
meusVeiculos.add(a);
}
}
jtb_Veiculos.setModel(model);
}
示例4: getTableCellRendererComponent
import javax.swing.table.DefaultTableCellRenderer; //導入依賴的package包/類
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
if (value == null) {
return new DefaultTableCellRenderer().getTableCellRendererComponent(table, value,
isSelected, hasFocus, row, column);
}
// This doesn't work in the presence of table row sorting:
//boolean isTotalRow = row == table.getModel().getRowCount()-1;
FileCoverageSummary summary = (FileCoverageSummary) table.getValueAt(row, -1);
boolean isTotalRow = summary == ((CoverageTableModel)table.getModel()).total;
setEmphasize(isTotalRow);
setSelected(isSelected);
float coverage = (Float) value;
setCoveragePercentage(coverage);
//setStats(summary.getLineCount(), summary.getExecutedLineCount(),
// summary.getInferredCount(), summary.getPartialCount());
return this;
}
示例5: getTableCellRendererComponent
import javax.swing.table.DefaultTableCellRenderer; //導入依賴的package包/類
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if(value instanceof String[]) {
this.box.setModel(new DefaultComboBoxModel((String[])(value)));
this.box.setSelectedItem(((DatabaseAdvancedConnectionDialog.DriverPropertyInfoTableModel)table.getModel()).getComboValue(table.convertRowIndexToModel(row)));
return this.box;
} else {
Component component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if(component instanceof DefaultTableCellRenderer && table.convertColumnIndexToModel(column) == 0) {
String tooltip = ((DatabaseAdvancedConnectionDialog.DriverPropertyInfoTableModel)table.getModel()).getTooltip(table.convertRowIndexToModel(row));
tooltip = "<html><div width = 300px>" + tooltip + "</div></html>";
((DefaultTableCellRenderer)component).setToolTipText(tooltip);
}
return component;
}
}
示例6: getCellRenderer
import javax.swing.table.DefaultTableCellRenderer; //導入依賴的package包/類
/**Returns combobox-styled cellrenderer if a multiple choice cell is to be rendered.
* @return cell renderer*/
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
//if this is type column, I must render it as a combo box instead of a jtextfield
if (column == 1) {
if (isLdEnabled()) {
return LD_enabled_StationTypeCell;
} else {
return LD_disabled_StationTypeCell;
}
} else if (column == getColumnCount() - 1) {
return deleteButtonCellRenderer;
} else {
return new DefaultTableCellRenderer();
}
}
示例7: getCellRenderer
import javax.swing.table.DefaultTableCellRenderer; //導入依賴的package包/類
/**Returns combobox-styled cellrenderer if a multiple choice cell is to be rendered.
* @return cell renderer*/
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
//if this is type column, I must render it as a combo box instead of a jtextfield
if (column == 1) {
if (LD_enabled_system) {
return LD_enabled_StationTypeCell;
} else {
return LD_disabled_StationTypeCell;
}
} else if (column == getColumnCount() - 1) {
return deleteButtonCellRenderer;
} else {
return new DefaultTableCellRenderer();
}
}
示例8: getCellRenderer
import javax.swing.table.DefaultTableCellRenderer; //導入依賴的package包/類
/**
* The original getCellRenderer method is overwritten, since the table
* displays in red the values that could not be calculated with the requested
* precision
* @param row the row of the cell
* @param column the column of the cell
* @return a the TableCellRenderer for the requested cell (row,column)
*/
public TableCellRenderer getCellRenderer(int row, int column) {
dtcr.setHorizontalAlignment(DefaultTableCellRenderer.CENTER);
//Component c = null;
Component c;
if (column < values.size()) {
c = dtcr.getTableCellRendererComponent(this, values.get(column), false, false, row, column);
if (!((PAResultsModel.MeasureValueImpl) values.get(column)).isValid()) {
c.setForeground(Color.RED);
} else {
c.setForeground(Color.BLACK);
}
} else {
c = dtcr.getTableCellRendererComponent(this, "-", false, false, row, column);
c.setForeground(Color.BLACK);
}
return dtcr;
}
示例9: 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);
}
示例10: getCellRenderer
import javax.swing.table.DefaultTableCellRenderer; //導入依賴的package包/類
/**
* The original getCellRenderer method is overwritten, since the table
* displays in red the values that could not be calculated with the requested
* precision
* @param row the row of the cell
* @param column the column of the cell
* @return a the TableCellRenderer for the requested cell (row,column)
*/
public TableCellRenderer getCellRenderer(int row, int column) {
dtcr.setHorizontalAlignment(DefaultTableCellRenderer.CENTER);
//Component c = null;
Component c;
if (column < values.size()) {
c = dtcr.getTableCellRendererComponent(this, values.get(column), false, false, row, column);
//if (!((Boolean)(validities.get(column))).booleanValue()) {
if (!((PAResultsModel.MeasureValueImpl) values.get(column)).isValid()) {
c.setForeground(Color.RED);
} else {
c.setForeground(Color.BLACK);
}
} else {
c = dtcr.getTableCellRendererComponent(this, "-", false, false, row, column);
c.setForeground(Color.BLACK);
}
return dtcr;
}
示例11: getTableCellRenderer
import javax.swing.table.DefaultTableCellRenderer; //導入依賴的package包/類
@Override
public TableCellRenderer getTableCellRenderer(Engine engine,
AccessRules rules, Attribute attribute) {
return new DefaultTableCellRenderer() {
/**
*
*/
private static final long serialVersionUID = -7922052040779840252L;
{
setHorizontalAlignment(SwingConstants.RIGHT);
}
@Override
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus,
int row, int column) {
Component component = super.getTableCellRendererComponent(
table, value, isSelected, hasFocus, row, column);
if (value != null)
((JLabel) component).setText(format(value));
return component;
}
};
}
示例12: getTableCellRenderer
import javax.swing.table.DefaultTableCellRenderer; //導入依賴的package包/類
@Override
public TableCellRenderer getTableCellRenderer(Engine engine,
AccessRules rules, Attribute attribute) {
return new DefaultTableCellRenderer() {
/**
*
*/
private static final long serialVersionUID = 6973511367750673696L;
@Override
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus,
int row, int column) {
return super.getTableCellRendererComponent(table,
MessageFormat
.format(GlobalResourcesManager
.getString("EmptyPlugin.Name"), type
.toString()), isSelected, hasFocus,
row, column);
}
};
}
示例13: PwnBackTable
import javax.swing.table.DefaultTableCellRenderer; //導入依賴的package包/類
PwnBackTable(PwnBackMediator mediator) {
this.mediator = mediator;
logTable.getModel().addTableModelListener(e -> {
if (TableUtilities.isInsert(e)) {
int viewRow = logTable.convertRowIndexToView(e.getFirstRow());
logTable.scrollRectToVisible(logTable.getCellRect(viewRow, 0, true));
}
});
logTable.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
final Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
c.setForeground(mediator.getLog().get(row).getRowColor());
return c;
}
});
}
示例14: runTest
import javax.swing.table.DefaultTableCellRenderer; //導入依賴的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);
}
示例15: createTableCellRenderer
import javax.swing.table.DefaultTableCellRenderer; //導入依賴的package包/類
private TableCellRenderer createTableCellRenderer() {
return new DefaultTableCellRenderer() {
private static final long serialVersionUID = 0L;
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Match match = (Match) value;
String text = "";
if(column == 0) {
text = Integer.toString(match.getMatchNumber());
} else if(column == 1) {
text = match.getGameType();
} else if(column == 2) {
text = match.getPlayerOne().getPlayerName();
} else if(column == 3) {
text = match.getPlayerTwo().getPlayerName();
}
return super.getTableCellRendererComponent(table, text, isSelected, hasFocus, row, column);
}
};
}