當前位置: 首頁>>代碼示例>>Java>>正文


Java DefaultTableCellRenderer.setBackground方法代碼示例

本文整理匯總了Java中javax.swing.table.DefaultTableCellRenderer.setBackground方法的典型用法代碼示例。如果您正苦於以下問題:Java DefaultTableCellRenderer.setBackground方法的具體用法?Java DefaultTableCellRenderer.setBackground怎麽用?Java DefaultTableCellRenderer.setBackground使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.table.DefaultTableCellRenderer的用法示例。


在下文中一共展示了DefaultTableCellRenderer.setBackground方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: checkTableGridLines

import javax.swing.table.DefaultTableCellRenderer; //導入方法依賴的package包/類
private static void checkTableGridLines() {

        TableModel dataModel = new AbstractTableModel() {
            public int getColumnCount() {
                return 10;
            }

            public int getRowCount() {
                return 10;
            }

            public Object getValueAt(int row, int col) {
                return " ";
            }
        };

        DefaultTableCellRenderer r = new DefaultTableCellRenderer();
        r.setOpaque(true);
        r.setBackground(CELL_RENDERER_BACKGROUND_COLOR);

        JTable table = new JTable(dataModel);
        table.setSize(WIDTH, HEIGHT);
        table.setDefaultRenderer(Object.class, r);
        table.setGridColor(GRID_COLOR);
        table.setShowGrid(true);
        table.setShowHorizontalLines(true);
        table.setShowVerticalLines(true);
        table.setBackground(TABLE_BACKGROUND_COLOR);

        checkTableGridLines(table);
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:32,代碼來源:DrawGridLinesTest.java

示例2: setCellBackground

import javax.swing.table.DefaultTableCellRenderer; //導入方法依賴的package包/類
public void setCellBackground(Color color, int columnindex) {
	if (columnindex < 0 || columnindex >= getColumnCount())
		return;

	DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
	TableColumn column = jtable.getTableHeader().getColumnModel()
			.getColumn(columnindex);
	renderer.setBackground(color);
	column.setCellRenderer(renderer);

}
 
開發者ID:Jasig,項目名稱:ImageQuiz,代碼行數:12,代碼來源:CheckBoxTable.java

示例3: interactiveTableCustomCoreRendererColor

import javax.swing.table.DefaultTableCellRenderer; //導入方法依賴的package包/類
/**
 * Issue #258-swingx: Background LegacyHighlighter must not change custom
 * foreground.
 * <p>
 * 
 * Visualizing effect of hack: table-internally, a ResetDTCRColorHighlighter
 * tries to neutralize DefaultTableCellRenderer's color memory.
 * 
 * <ul>
 * <li> a DTCR with custom foreground and custom background
 * <li> the renderer is shared between a table with background highlighter
 * (alternateRowHighlighter) and a table without highlighter
 * <li> the custom foreground must show in both
 * <li> the custom background must show in the table without highlighter
 * <li> the custom background must not show in the table with highlighter
 * (AlternateRowHighlighter overwrite both striped and unstriped back)
 * </ul>
 * 
 */
public void interactiveTableCustomCoreRendererColor() {
    TableModel model = new AncientSwingTeam();
    JXTable table = new JXTable(model);
    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
    renderer.setForeground(foreground);
    renderer.setBackground(background);
    table.addHighlighter(
            HighlighterFactory.createSimpleStriping(HighlighterFactory.GENERIC_GRAY));

    table.setDefaultRenderer(Object.class, renderer);
    JXTable nohighlight = new JXTable(model);
    nohighlight.setDefaultRenderer(Object.class, renderer);
    showWithScrollingInFrame(table, nohighlight,
            "core: custom colored renderer with bg highlighter <--> shared without highl");
}
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:35,代碼來源:HighlighterIssues.java

示例4: createTemplatePanel

import javax.swing.table.DefaultTableCellRenderer; //導入方法依賴的package包/類
public JPanel createTemplatePanel()
{
    JPanel panel = new JPanel();
    panel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
    panel.setPreferredSize(new Dimension(Editor.TEMPLATE_BLOCK_WIDTH,Editor.TEMPLATE_BLOCK_HEIGHT));
    panel.setLayout(new BorderLayout());
    panel.setBackground(Color.WHITE);

    templateTable  = new JTable(new TemplateModel(new ArrayList<Template>()));
    templateTable.setGridColor(Color.WHITE);
    templateTable.setDefaultRenderer(templateTable.getColumnClass(0), new ColorCellRenderer());
    DefaultTableCellRenderer tableCellRenderer = (DefaultTableCellRenderer)templateTable.getDefaultRenderer(String.class);
    tableCellRenderer.setBackground(Color.WHITE);
    templateTable.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e){
            if (e.getClickCount() == 2){
                int row = ((JTable)e.getSource()).getSelectedRow();
                performTemplate(row);
            }
        }
    });

    panel.add(templateTable,BorderLayout.NORTH);
    
    JPanel isButtonPanel = new JPanel();
    isButtonPanel.setLayout(new BoxLayout(isButtonPanel,BoxLayout.X_AXIS));
    isButtonPanel.setBackground(Color.WHITE);
    isButtonPanel.setPreferredSize(new Dimension(Editor.IS_BLOCK_WIDTH,Editor.BUTTON_PANEL_HEIGHT));

    JButton applyButton = new JButton(APPLYALL);
    applyButton.addActionListener(new ActionListener(){
        @Override
        public void actionPerformed(ActionEvent arg0) {
            performAllTemplates();
        }
    });
    isButtonPanel.add(applyButton);
    
    panel.add(isButtonPanel,BorderLayout.SOUTH);

    return panel;
}
 
開發者ID:ARIA-VALUSPA,項目名稱:Flipper,代碼行數:43,代碼來源:RunnerPanel.java


注:本文中的javax.swing.table.DefaultTableCellRenderer.setBackground方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。