javax.swing.table.DefaultTableCellRenderer Java Examples

The following examples show how to use javax.swing.table.DefaultTableCellRenderer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TaskList.java    From swift-k with Apache License 2.0 8 votes vote down vote up
public TaskList(TaskHandler handler) {
	this();
	this.handler = handler;
	model = new SingleHandlerTaskModel(handler);
	table = new JTable(model);
	table.setAutoCreateColumnsFromModel(true);
	table.setDefaultRenderer(String.class, new DefaultTableCellRenderer());
	getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);
	update(0,0);
	table.setSize(640,200);
	table.setPreferredSize(new Dimension(640, 200));
	pack();
}
 
Example #2
Source File: HttpRequestForm.java    From MooTool with MIT License 7 votes vote down vote up
/**
 * 初始化CookieTable
 */
public static void initCookieTable() {
    JTable paramTable = getInstance().getCookieTable();
    paramTable.setRowHeight(36);
    String[] headerNames = {"Name", "Value", "Domain", "Path", "Expiry", ""};
    DefaultTableModel model = new DefaultTableModel(null, headerNames);
    paramTable.setModel(model);
    paramTable.updateUI();
    DefaultTableCellRenderer hr = (DefaultTableCellRenderer) paramTable.getTableHeader().getDefaultRenderer();
    // 表头列名居左
    hr.setHorizontalAlignment(DefaultTableCellRenderer.LEFT);

    TableColumnModel tableColumnModel = paramTable.getColumnModel();
    tableColumnModel.getColumn(headerNames.length - 1).
            setCellRenderer(new TableInCellButtonColumn(paramTable, headerNames.length - 1));
    tableColumnModel.getColumn(headerNames.length - 1).
            setCellEditor(new TableInCellButtonColumn(paramTable, headerNames.length - 1));

    // 设置列宽
    tableColumnModel.getColumn(headerNames.length - 1).setPreferredWidth(46);
    tableColumnModel.getColumn(headerNames.length - 1).setMaxWidth(46);
}
 
Example #3
Source File: DateTableEditor.java    From LGoodDatePicker with MIT License 7 votes vote down vote up
/**
 * Constructor, with options.
 *
 * @param autoAdjustMinimumTableRowHeight Set this to true to have this class automatically
 * adjust the the minimum row height of all rows in the table, the first time that a
 * DateTableEditor is displayed. Set this to false to turn off any row height adjustments. The
 * default value is true.
 *
 * @param matchTableBackgroundColor This indicates whether this table editor should set the
 * picker text area background color to match the background color of the table. The default
 * value is true.
 *
 * @param matchTableSelectionBackgroundColor This indicates whether this table editor should set
 * the picker text area background color to match the background color of the table selection
 * (when selected). The default value is true.
 */
public DateTableEditor(boolean autoAdjustMinimumTableRowHeight,
        boolean matchTableBackgroundColor, boolean matchTableSelectionBackgroundColor) {
    // Save the constructor parameters.
    this.autoAdjustMinimumTableRowHeight = autoAdjustMinimumTableRowHeight;
    this.matchTableBackgroundColor = matchTableBackgroundColor;
    this.matchTableSelectionBackgroundColor = matchTableSelectionBackgroundColor;
    // Create the borders that should be used for focused and unfocused cells.
    JLabel exampleDefaultRenderer = (JLabel) new DefaultTableCellRenderer().
            getTableCellRendererComponent(new JTable(), "", true, true, 0, 0);
    borderFocusedCell = exampleDefaultRenderer.getBorder();
    borderUnfocusedCell = new EmptyBorder(1, 1, 1, 1);
    // Create and set up the date picker.
    datePicker = new DatePicker();
    datePicker.setBorder(borderUnfocusedCell);
    datePicker.getComponentDateTextField().setBorder(null);
    // Adjust any needed date picker settings.
    DatePickerSettings settings = datePicker.getSettings();
    settings.setGapBeforeButtonPixels(0);
    settings.setSizeTextFieldMinimumWidthDefaultOverride(false);
    settings.setSizeTextFieldMinimumWidth(20);
    // Calculate and store the minimum row height needed to display the date picker.
    minimumRowHeightInPixels = (datePicker.getPreferredSize().height + 1);
}
 
Example #4
Source File: EmptyPlugin.java    From ramus with GNU General Public License v3.0 7 votes vote down vote up
@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);
        }
    };
}
 
Example #5
Source File: EconomyPanel.java    From triplea with GNU General Public License v3.0 6 votes vote down vote up
protected void initLayout() {
  setLayout(new GridLayout(1, 1));
  resourceModel = new ResourceTableModel();
  final JTable table = new JTable(resourceModel);
  table.getTableHeader().setReorderingAllowed(false);
  final TableColumn column = table.getColumnModel().getColumn(0);
  column.setPreferredWidth(175);
  for (int i = 1; i < resourceModel.getColumnCount(); i++) {
    table.getColumnModel().getColumn(i).setHeaderRenderer(new DefaultTableCellRenderer());
    final JLabel label = (JLabel) table.getColumnModel().getColumn(i).getHeaderRenderer();
    final Resource resource = resourceStats.get(i - 1).resource;
    try {
      label.setIcon(uiContext.getResourceImageFactory().getIcon(resource, false));
      label.setToolTipText(resource.getName());
    } catch (final IllegalStateException e) {
      // ignore missing resource image
    }
  }
  final JScrollPane scroll = new JScrollPane(table);
  add(scroll);
}
 
Example #6
Source File: SettingsDialog.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private JPanel buildWorkPanel() {
	JPanel workPanel = new JPanel(new BorderLayout());
	workPanel.setBorder(new EmptyBorder(10, 10, 10, 10));

	settingsTableModel = new SettingsTableModel();
	settingsTable = new GTable(settingsTableModel);
	settingsTable.setAutoscrolls(true);
	settingsTable.setRowSelectionAllowed(false);
	settingsTable.setColumnSelectionAllowed(false);

	// disable sorting and column adding (we don't expect enough data to require sort changes)
	settingsTable.getTableHeader().setReorderingAllowed(false);
	settingsTable.setColumnHeaderPopupEnabled(false);
	settingsTable.setUserSortingEnabled(false);

	settingsTable.setDefaultRenderer(Settings.class, new DefaultTableCellRenderer());
	settingsTable.setDefaultEditor(Settings.class, new SettingsEditor());

	JScrollPane scrollpane = new JScrollPane(settingsTable);
	scrollpane.setPreferredSize(new Dimension(WIDTH, HEIGHT));

	workPanel.add(scrollpane, BorderLayout.CENTER);

	return workPanel;
}
 
Example #7
Source File: FieldsTableDelegate.java    From haystack with MIT License 6 votes vote down vote up
public void setClass(ClassModel classModel) {
    fieldsData = classModel.getFields();
    fieldsTable.setModel(new FieldsTableModel(fieldsData));

    TableColumn column = fieldsTable.getColumnModel().getColumn(0);
    column.setPreferredWidth(30);
    fieldsTable.getColumnModel().getColumn(1).setPreferredWidth(30);

    TableColumn modifierColumn = fieldsTable.getColumnModel().getColumn(3);
    ComboBox<String> modifierCombobox = new ComboBox<>();
    List<String> typeList = languageResolver.getSupportTypeList();
    for (int i = 0; i < typeList.size(); i++) {
        modifierCombobox.addItem(typeList.get(i));
    }

    modifierColumn.setCellEditor(new DefaultCellEditor(modifierCombobox));

    DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
    centerRenderer.setHorizontalAlignment(JLabel.CENTER);
    for (int i = 2; i < columns.length; i++) {
        fieldsTable.getColumnModel().getColumn(i).setCellRenderer(centerRenderer);
    }
}
 
Example #8
Source File: MaSubscribeMsgForm.java    From WePush with MIT License 6 votes vote down vote up
/**
 * 初始化模板消息数据table
 */
public static void initTemplateDataTable() {
    JTable msgDataTable = getInstance().getTemplateMsgDataTable();
    String[] headerNames = {"Name", "Value", "Color", "操作"};
    DefaultTableModel model = new DefaultTableModel(null, headerNames);
    msgDataTable.setModel(model);
    msgDataTable.updateUI();
    DefaultTableCellRenderer hr = (DefaultTableCellRenderer) msgDataTable.getTableHeader().getDefaultRenderer();
    // 表头列名居左
    hr.setHorizontalAlignment(DefaultTableCellRenderer.LEFT);

    TableColumnModel tableColumnModel = msgDataTable.getColumnModel();
    tableColumnModel.getColumn(headerNames.length - 1).
            setCellRenderer(new TableInCellButtonColumn(msgDataTable, headerNames.length - 1));
    tableColumnModel.getColumn(headerNames.length - 1).
            setCellEditor(new TableInCellButtonColumn(msgDataTable, headerNames.length - 1));

    // 设置列宽
    tableColumnModel.getColumn(3).setPreferredWidth(46);
    tableColumnModel.getColumn(3).setMaxWidth(46);
}
 
Example #9
Source File: HttpMsgForm.java    From WePush with MIT License 6 votes vote down vote up
/**
 * 初始化HeaderTable
 */
public static void initHeaderTable() {
    JTable paramTable = getInstance().getHeaderTable();
    paramTable.setRowHeight(36);
    String[] headerNames = {"Name", "Value", ""};
    DefaultTableModel model = new DefaultTableModel(null, headerNames);
    paramTable.setModel(model);
    paramTable.updateUI();
    DefaultTableCellRenderer hr = (DefaultTableCellRenderer) paramTable.getTableHeader().getDefaultRenderer();
    // 表头列名居左
    hr.setHorizontalAlignment(DefaultTableCellRenderer.LEFT);

    TableColumnModel tableColumnModel = paramTable.getColumnModel();
    tableColumnModel.getColumn(headerNames.length - 1).
            setCellRenderer(new TableInCellButtonColumn(paramTable, headerNames.length - 1));
    tableColumnModel.getColumn(headerNames.length - 1).
            setCellEditor(new TableInCellButtonColumn(paramTable, headerNames.length - 1));

    // 设置列宽
    tableColumnModel.getColumn(headerNames.length - 1).setPreferredWidth(46);
    tableColumnModel.getColumn(headerNames.length - 1).setMaxWidth(46);
}
 
Example #10
Source File: PushHisForm.java    From WePush with MIT License 6 votes vote down vote up
private static void initHisLeftTable() {
    // 导入历史管理
    String[] headerNames = {"消息名称", "状态", "时间", "id"};
    DefaultTableModel model = new DefaultTableModel(null, headerNames);
    pushHisForm.getPushHisLeftTable().setModel(model);

    DefaultTableCellRenderer hr = (DefaultTableCellRenderer) pushHisForm.getPushHisLeftTable().getTableHeader()
            .getDefaultRenderer();
    // 表头列名居左
    hr.setHorizontalAlignment(DefaultTableCellRenderer.LEFT);

    List<TPushHistory> pushHistoryList = pushHistoryMapper.selectByMsgType(App.config.getMsgType());
    Object[] data;
    for (TPushHistory tPushHistory : pushHistoryList) {
        data = new Object[4];
        data[0] = tPushHistory.getMsgName();
        data[1] = tPushHistory.getResult();
        data[2] = tPushHistory.getCreateTime();
        data[3] = tPushHistory.getId();
        model.addRow(data);
    }

    // 隐藏id列
    JTableUtil.hideColumn(pushHisForm.getPushHisLeftTable(), 3);
}
 
Example #11
Source File: TableUIBridge.java    From darklaf with MIT License 6 votes vote down vote up
/**
 * Returns the baseline.
 *
 * @throws NullPointerException     {@inheritDoc}
 * @throws IllegalArgumentException {@inheritDoc}
 * @see                             javax.swing.JComponent#getBaseline(int, int)
 * @since                           1.6
 */
public int getBaseline(final JComponent c, final int width, final int height) {
    super.getBaseline(c, width, height);
    UIDefaults lafDefaults = UIManager.getLookAndFeelDefaults();
    Component renderer = (Component) lafDefaults.get(BASELINE_COMPONENT_KEY);
    if (renderer == null) {
        DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();
        renderer = tcr.getTableCellRendererComponent(table, "a", false, false, -1, -1);
        lafDefaults.put(BASELINE_COMPONENT_KEY, renderer);
    }
    renderer.setFont(table.getFont());
    int rowMargin = table.getRowMargin();
    return renderer.getBaseline(Integer.MAX_VALUE, table.getRowHeight() -
                                                   rowMargin)
           + rowMargin / 2;
}
 
Example #12
Source File: AliYunMsgForm.java    From WePush with MIT License 6 votes vote down vote up
/**
 * 初始化模板消息数据table
 */
public static void initTemplateDataTable() {
    JTable msgDataTable = getInstance().getTemplateMsgDataTable();
    String[] headerNames = {"模板参数", "参数对应的值", "操作"};
    DefaultTableModel model = new DefaultTableModel(null, headerNames);
    msgDataTable.setModel(model);
    msgDataTable.updateUI();
    DefaultTableCellRenderer hr = (DefaultTableCellRenderer) msgDataTable.getTableHeader().getDefaultRenderer();
    // 表头列名居左
    hr.setHorizontalAlignment(DefaultTableCellRenderer.LEFT);

    TableColumnModel tableColumnModel = msgDataTable.getColumnModel();
    tableColumnModel.getColumn(headerNames.length - 1).
            setCellRenderer(new TableInCellButtonColumn(msgDataTable, headerNames.length - 1));
    tableColumnModel.getColumn(headerNames.length - 1).
            setCellEditor(new TableInCellButtonColumn(msgDataTable, headerNames.length - 1));

    // 设置列宽
    tableColumnModel.getColumn(2).setPreferredWidth(46);
    tableColumnModel.getColumn(2).setMaxWidth(46);
}
 
Example #13
Source File: HttpRequestForm.java    From MooTool with MIT License 6 votes vote down vote up
/**
 * 初始化HeaderTable
 */
public static void initHeaderTable() {
    JTable paramTable = getInstance().getHeaderTable();
    paramTable.setRowHeight(36);
    String[] headerNames = {"Name", "Value", ""};
    DefaultTableModel model = new DefaultTableModel(null, headerNames);
    paramTable.setModel(model);
    paramTable.updateUI();
    DefaultTableCellRenderer hr = (DefaultTableCellRenderer) paramTable.getTableHeader().getDefaultRenderer();
    // 表头列名居左
    hr.setHorizontalAlignment(DefaultTableCellRenderer.LEFT);

    TableColumnModel tableColumnModel = paramTable.getColumnModel();
    tableColumnModel.getColumn(headerNames.length - 1).
            setCellRenderer(new TableInCellButtonColumn(paramTable, headerNames.length - 1));
    tableColumnModel.getColumn(headerNames.length - 1).
            setCellEditor(new TableInCellButtonColumn(paramTable, headerNames.length - 1));

    // 设置列宽
    tableColumnModel.getColumn(headerNames.length - 1).setPreferredWidth(46);
    tableColumnModel.getColumn(headerNames.length - 1).setMaxWidth(46);
}
 
Example #14
Source File: HwYunMsgForm.java    From WePush with MIT License 6 votes vote down vote up
/**
 * 初始化模板消息数据table
 */
public static void initTemplateDataTable() {
    JTable msgDataTable = getInstance().getTemplateMsgDataTable();
    String[] headerNames = {"模板参数", "参数对应的值", "操作"};
    DefaultTableModel model = new DefaultTableModel(null, headerNames);
    msgDataTable.setModel(model);
    msgDataTable.updateUI();
    DefaultTableCellRenderer hr = (DefaultTableCellRenderer) msgDataTable.getTableHeader().getDefaultRenderer();
    // 表头列名居左
    hr.setHorizontalAlignment(DefaultTableCellRenderer.LEFT);

    TableColumnModel tableColumnModel = msgDataTable.getColumnModel();
    tableColumnModel.getColumn(headerNames.length - 1).
            setCellRenderer(new TableInCellButtonColumn(msgDataTable, headerNames.length - 1));
    tableColumnModel.getColumn(headerNames.length - 1).
            setCellEditor(new TableInCellButtonColumn(msgDataTable, headerNames.length - 1));

    // 设置列宽
    tableColumnModel.getColumn(2).setPreferredWidth(46);
    tableColumnModel.getColumn(2).setMaxWidth(46);
}
 
Example #15
Source File: DistanceTableCellRenderer.java    From dsworkbench with Apache License 2.0 6 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
    Component c = renderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    JLabel l = (JLabel) c;
    double v = (Double) value;
    if (unit.equals(UnknownUnit.getSingleton())) {
        l.setText(nf.format(value));
    } else {
        double speedInMinutes = v * unit.getSpeed();
        l.setText(DSCalculator.formatTimeInMinutes(speedInMinutes));
    }

    Color col = null;
    if (v <= markerMin) {
        col = ColorGradientHelper.getGradientColor(100f, Color.RED, Color.GREEN);
    } else if ((v > markerMin) && (v < markerMax)) {
        double range = markerMax - markerMin;
        double val = v - markerMin;
        col = ColorGradientHelper.getGradientColor((float) (100.0 - (100.0 * val / range)), Color.RED, Color.GREEN);
    } else if (v >= markerMax) {
        col = ColorGradientHelper.getGradientColor(0f, Color.RED, Color.GREEN);
    }
    c.setBackground(col);
    return c;
}
 
Example #16
Source File: MaTemplateMsgForm.java    From WePush with MIT License 6 votes vote down vote up
/**
 * 初始化模板消息数据table
 */
public static void initTemplateDataTable() {
    JTable msgDataTable = getInstance().getTemplateMsgDataTable();
    String[] headerNames = {"Name", "Value", "Color", "操作"};
    DefaultTableModel model = new DefaultTableModel(null, headerNames);
    msgDataTable.setModel(model);
    msgDataTable.updateUI();
    DefaultTableCellRenderer hr = (DefaultTableCellRenderer) msgDataTable.getTableHeader().getDefaultRenderer();
    // 表头列名居左
    hr.setHorizontalAlignment(DefaultTableCellRenderer.LEFT);

    TableColumnModel tableColumnModel = msgDataTable.getColumnModel();
    tableColumnModel.getColumn(headerNames.length - 1).
            setCellRenderer(new TableInCellButtonColumn(msgDataTable, headerNames.length - 1));
    tableColumnModel.getColumn(headerNames.length - 1).
            setCellEditor(new TableInCellButtonColumn(msgDataTable, headerNames.length - 1));

    // 设置列宽
    tableColumnModel.getColumn(3).setPreferredWidth(46);
    tableColumnModel.getColumn(3).setMaxWidth(46);
}
 
Example #17
Source File: ProjectSettingsPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
public TableCellRenderer getRenderer(final ScopeSetting scopeSetting) {
  return new DefaultTableCellRenderer() {
    public Component getTableCellRendererComponent(JTable table,
                                                   Object value,
                                                   boolean isSelected,
                                                   boolean hasFocus,
                                                   int row,
                                                   int column) {
      final Component rendererComponent = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
      if (!isSelected) {
        final CopyrightProfile profile = myProfilesModel.getAllProfiles().get(scopeSetting.getProfileName());
        setForeground(profile == null ? JBColor.RED : UIUtil.getTableForeground());
      }
      setText(scopeSetting.getProfileName());
      return rendererComponent;
    }
  };
}
 
Example #18
Source File: DingAppDialog.java    From WePush with MIT License 6 votes vote down vote up
/**
 * 应用列表表格
 */
public void renderTable() {
    String[] headerNames = {"id", "应用名称", "AgentId", "AppKey", "AppSecret"};
    DefaultTableModel model = new DefaultTableModel(null, headerNames);
    appsTable.setModel(model);

    DefaultTableCellRenderer hr = (DefaultTableCellRenderer) appsTable.getTableHeader().getDefaultRenderer();
    // 表头列名居左
    hr.setHorizontalAlignment(DefaultTableCellRenderer.LEFT);

    List<TDingApp> dingAppList = dingAppMapper.selectAll();
    Object[] data;
    for (TDingApp tDingApp : dingAppList) {
        data = new Object[5];
        data[0] = tDingApp.getId();
        data[1] = tDingApp.getAppName();
        data[2] = tDingApp.getAgentId();
        data[3] = tDingApp.getAppKey();
        data[4] = tDingApp.getAppSecret();
        model.addRow(data);
    }

    // 隐藏id列
    JTableUtil.hideColumn(appsTable, 0);
}
 
Example #19
Source File: TableRenderDemo.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #20
Source File: WxCpAppDialog.java    From WePush with MIT License 6 votes vote down vote up
/**
 * 应用列表表格
 */
public void renderTable() {
    String[] headerNames = {"id", "应用名称", "AgentId", "Secret"};
    DefaultTableModel model = new DefaultTableModel(null, headerNames);
    appsTable.setModel(model);

    DefaultTableCellRenderer hr = (DefaultTableCellRenderer) appsTable.getTableHeader()
            .getDefaultRenderer();
    // 表头列名居左
    hr.setHorizontalAlignment(DefaultTableCellRenderer.LEFT);

    List<TWxCpApp> wxCpAppList = wxCpAppMapper.selectAll();
    Object[] data;
    for (TWxCpApp tWxCpApp : wxCpAppList) {
        data = new Object[4];
        data[0] = tWxCpApp.getId();
        data[1] = tWxCpApp.getAppName();
        data[2] = tWxCpApp.getAgentId();
        data[3] = tWxCpApp.getSecret();
        model.addRow(data);
    }

    // 隐藏id列
    JTableUtil.hideColumn(appsTable, 0);
}
 
Example #21
Source File: ResamplingUtils.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
public static void setUpDownsamplingColumn(JTable table,
                                            TableColumn downsamplingColumn, String defaultDownsampling) {
    //Set up the editor for the downsampling
    JComboBox comboBox = new JComboBox();
    for ( String alias : (Set<String>) GPF.getDefaultInstance().getDownsamplerSpiRegistry().getAliases()) {
        comboBox.addItem(alias);
    }

    if(defaultDownsampling != null) {
        comboBox.setSelectedItem(defaultDownsampling);
    }
    downsamplingColumn.setCellEditor(new DefaultCellEditor(comboBox));

    DefaultTableCellRenderer renderer =
            new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for combo box");
    downsamplingColumn.setCellRenderer(renderer);
}
 
Example #22
Source File: CoverageReportTopComponent.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #23
Source File: AlertedCardsRenderer.java    From MtgDesktopCompanion with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,int row, int column) {
	Component comp = new DefaultTableCellRenderer().getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
	comp.setForeground(Color.BLACK);
	
	
	
	if ((Integer) value > 0)
		comp.setBackground(Color.GREEN);
	else if(isSelected)
		comp.setBackground(table.getSelectionBackground());
	else
		comp.setBackground(table.getBackground());
	
	
	return comp;
}
 
Example #24
Source File: QiNiuYunMsgForm.java    From WePush with MIT License 6 votes vote down vote up
/**
 * 初始化模板消息数据table
 */
public static void initTemplateDataTable() {
    JTable msgDataTable = getInstance().getTemplateMsgDataTable();
    String[] headerNames = {"模板参数", "参数对应的值", "操作"};
    DefaultTableModel model = new DefaultTableModel(null, headerNames);
    msgDataTable.setModel(model);
    msgDataTable.updateUI();
    DefaultTableCellRenderer hr = (DefaultTableCellRenderer) msgDataTable.getTableHeader().getDefaultRenderer();
    // 表头列名居左
    hr.setHorizontalAlignment(DefaultTableCellRenderer.LEFT);

    TableColumnModel tableColumnModel = msgDataTable.getColumnModel();
    tableColumnModel.getColumn(headerNames.length - 1).
            setCellRenderer(new TableInCellButtonColumn(msgDataTable, headerNames.length - 1));
    tableColumnModel.getColumn(headerNames.length - 1).
            setCellEditor(new TableInCellButtonColumn(msgDataTable, headerNames.length - 1));

    // 设置列宽
    tableColumnModel.getColumn(2).setPreferredWidth(46);
    tableColumnModel.getColumn(2).setMaxWidth(46);
}
 
Example #25
Source File: PropertyEditorTable.java    From workcraft with MIT License 5 votes vote down vote up
private void update() {
    cellRenderers = new TableCellRenderer[model.getRowCount()];
    cellEditors = new TableCellEditor[model.getRowCount()];
    for (int i = 0; i < model.getRowCount(); i++) {
        PropertyDescriptor decl = model.getDeclaration(i);
        if (decl.getChoice() != null) {
            // If object declares a predefined set of values, use a ComboBox to edit the property regardless of class
            model.setRowClass(i, null);
            cellRenderers[i] = new ChoiceCellRenderer();
            cellEditors[i] = new ChoiceCellEditor(decl);
        } else {
            // otherwise, try to get a corresponding PropertyClass object, that knows how to edit a property of this class
            Class type = decl.getType();
            PropertyClass cls = propertyClasses.get(type);
            model.setRowClass(i, cls);
            if (cls != null) {
                cellRenderers[i] = cls.getCellRenderer();
                cellEditors[i] = cls.getCellEditor();
            } else {
                // no PropertyClass exists for this class, fall back to read-only mode using Object.toString()
                System.err.println("Data class '" + type.getName() + "' is not supported by the Property editor.");
                cellRenderers[i] = new DefaultTableCellRenderer();
                cellEditors[i] = null;
            }
        }
    }
}
 
Example #26
Source File: FormulaFragmentCellRenderer.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public FormulaFragmentCellRenderer() {
  tableCellRenderer = new DefaultTableCellRenderer();
  tableCellRenderer.putClientProperty( "html.disable", Boolean.TRUE ); // NON-NLS

  listCellRenderer = new DefaultListCellRenderer();
  listCellRenderer.putClientProperty( "html.disable", Boolean.TRUE ); // NON-NLS
}
 
Example #27
Source File: XTable.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #28
Source File: XTable.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #29
Source File: PaddingTableCellRenderer.java    From jeveassets with GNU General Public License v2.0 5 votes vote down vote up
private PaddingTableCellRenderer(final TableCellRenderer renderer, final int top, final int left, final int bottom, final int right) {
	if (renderer != null) {
		this.renderer = renderer;
	} else {
		this.renderer = new DefaultTableCellRenderer();
	}
	border = BorderFactory.createEmptyBorder(top, left, bottom, right);
}
 
Example #30
Source File: CertificatesManagerSettingsPanel.java    From Spark with Apache License 2.0 5 votes vote down vote up
public void addCertTableToPanel() {
    certControll.loadKeyStores();
    certControll.createTableModel();
    certTable = new JTable(certControll.getTableModel()){
        
        @Override
        public Component prepareRenderer(TableCellRenderer renderer, int rowIndex,
                int columnIndex) {
            JComponent component = (JComponent) super.prepareRenderer(renderer, rowIndex, columnIndex);  
            Object value = getModel().getValueAt(convertRowIndexToModel(rowIndex), columnIndex);
            
            DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
            centerRenderer.setHorizontalAlignment( JLabel.CENTER );
            this.getColumnModel().getColumn(1).setCellRenderer(centerRenderer);
            
            
             if (value.equals(Res.getString("cert.valid"))) {
                component.setBackground(Color.green);
            } else if (value.equals(Res.getString("cert.expired")) || value
                    .equals(Res.getString("cert.not.valid.yet")) || value.equals(Res.getString("cert.revoked"))) {
                component.setBackground(Color.red);
            } else {
               component.setBackground(Color.white);
            }
            return component;
        }  
    };

    
    scrollPane = new JScrollPane(certTable);
    certTable.setFillsViewportHeight(true);
    certTable.setAutoCreateRowSorter(true);
    
    certControll.resizeColumnWidth(certTable);
    certTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);

    
}