Java Code Examples for javax.swing.table.DefaultTableCellRenderer

The following examples show how to use javax.swing.table.DefaultTableCellRenderer. These examples are extracted from open source projects. 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 Project: ramus   Source File: EmptyPlugin.java    License: 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 2
Source Project: LGoodDatePicker   Source File: DateTableEditor.java    License: 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 3
Source Project: triplea   Source File: EconomyPanel.java    License: 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 4
Source Project: MooTool   Source File: HttpRequestForm.java    License: 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 5
Source Project: MooTool   Source File: HttpRequestForm.java    License: MIT License 6 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 6
Source Project: darklaf   Source File: TableUIBridge.java    License: 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 7
Source Project: haystack   Source File: FieldsTableDelegate.java    License: 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 Project: ghidra   Source File: SettingsDialog.java    License: 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 9
Source Project: dsworkbench   Source File: DistanceTableCellRenderer.java    License: 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 10
Source Project: marathonv5   Source File: TableRenderDemo.java    License: 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 11
Source Project: snap-desktop   Source File: ResamplingUtils.java    License: 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 12
Source Project: netbeans   Source File: CoverageReportTopComponent.java    License: 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 13
@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 14
Source Project: WePush   Source File: WxCpAppDialog.java    License: 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 15
Source Project: swift-k   Source File: TaskList.java    License: Apache License 2.0 6 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 16
Source Project: WePush   Source File: DingAppDialog.java    License: 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 17
Source Project: WePush   Source File: QiNiuYunMsgForm.java    License: 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 18
Source Project: consulo   Source File: ProjectSettingsPanel.java    License: 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 19
Source Project: WePush   Source File: MaTemplateMsgForm.java    License: 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 20
Source Project: WePush   Source File: HwYunMsgForm.java    License: 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 21
Source Project: WePush   Source File: AliYunMsgForm.java    License: 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 22
Source Project: WePush   Source File: MaSubscribeMsgForm.java    License: 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 23
Source Project: WePush   Source File: HttpMsgForm.java    License: 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 24
Source Project: WePush   Source File: PushHisForm.java    License: 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 25
Source Project: MooTool   Source File: JTableUtil.java    License: MIT License 5 votes vote down vote up
/**
 * 隐藏表头
 *
 * @param table
 */
public static void hideTableHeader(JTable table) {
    table.getTableHeader().setVisible(false);
    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
    renderer.setPreferredSize(new Dimension(0, 0));
    table.getTableHeader().setDefaultRenderer(renderer);
}
 
Example 26
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
    int row, int column) {
  Component cellRendererComp =
      delegate.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

  if (cellRendererComp instanceof DefaultTableCellRenderer) {
    ((DefaultTableCellRenderer) cellRendererComp).setHorizontalAlignment(alignment);
  }

  return cellRendererComp;
}
 
Example 27
Source Project: cstc   Source File: VariablesWindow.java    License: GNU General Public License v3.0 5 votes vote down vote up
private VariablesWindow() {
	super("Variables");
	this.setSize(new Dimension(600, 480));

	DefaultTableModel model = new DefaultTableModel(new String[] { "Variable Name", "Content" }, 0);
	this.table = new JTable(model) {
		public boolean isCellEditable(int row, int column) {
			return false;
		};
	};
	
	this.addComponentListener(new ComponentAdapter() {
		public void componentResized(ComponentEvent e) {
			if (table.getModel().getRowCount() == 0) {
				setColumnWidth(new Dimension());		
			}
		}
	});
	
	this.table.setLayout(new GridBagLayout());
	this.table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
	this.table.getColumnModel().getColumn(0).setPreferredWidth(200);
	this.table.getColumnModel().getColumn(1).setCellRenderer(new WordWrapCellRenderer());
	this.table.getTableHeader().setReorderingAllowed(false);
    this.table.getTableHeader().setResizingAllowed(false);
    this.table.setFillsViewportHeight(true);
    ((DefaultTableCellRenderer)table.getTableHeader().getDefaultRenderer()).setHorizontalAlignment(JLabel.LEFT);
    
    this.emptyLbl = new JLabel("no variables defined");
    this.table.add(this.emptyLbl);
    
	JScrollPane scrollPane = new JScrollPane(this.table);
	this.add(scrollPane);
}
 
Example 28
/**
 * 
 */
PeakListTableColumnModel(GroupableTableHeader header, PeakListTableModel tableModel,
    ParameterSet parameters, PeakList peakList) {

  this.parameters = parameters;
  this.peakList = peakList;

  this.header = header;

  header.addMouseListener(this);

  // prepare formatters
  NumberFormat mzFormat = MZmineCore.getConfiguration().getMZFormat();
  NumberFormat rtFormat = MZmineCore.getConfiguration().getRTFormat();
  NumberFormat intensityFormat = MZmineCore.getConfiguration().getIntensityFormat();

  // prepare cell renderers
  mzRenderer = new FormattedCellRenderer(mzFormat);
  rtRenderer = new FormattedCellRenderer(rtFormat);
  intensityRenderer = new FormattedCellRenderer(intensityFormat);
  peakShapeRenderer = new PeakShapeCellRenderer(peakList, parameters);
  identityRenderer = new CompoundIdentityCellRenderer();
  peakStatusRenderer = new PeakStatusCellRenderer();
  defaultRenderer = new DefaultTableCellRenderer();
  defaultRenderer.setHorizontalAlignment(SwingConstants.CENTER);
  defaultRendererLeft = new DefaultTableCellRenderer();
  defaultRendererLeft.setHorizontalAlignment(SwingConstants.LEFT);
  datapointsRenderer = new FormattedCellRenderer(new DecimalFormat());
  qcRenderer = new FormattedCellRenderer(new DecimalFormat());

}
 
Example 29
Source Project: dsworkbench   Source File: StorageCellRenderer.java    License: Apache License 2.0 5 votes vote down vote up
public StorageCellRenderer() {
    super();
    renderer = new DefaultTableCellRenderer();
    label = new FillingLabel();
    label.setOpaque(true);
    label.setColors(new Color[]{new Color(187, 148, 70), new Color(242, 131, 30), new Color(224, 211, 209)});
}
 
Example 30
Source Project: consulo   Source File: DetectedRootsChooserDialog.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public TableCellRenderer getRenderer(VirtualFileCheckedTreeNode node) {
  final SuggestedChildRootInfo rootInfo = node.getRootInfo();
  if (rootInfo != null && isCellEditable(node)) {
    return new ComboBoxTableRenderer<String>(rootInfo.getRootTypeNames());
  }
  return new DefaultTableCellRenderer();
}