Java 8 JTableHeader - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 JTableHeader class.

This code example shows how to use the following methods:addMouseListener, getBackground, getFont, getForeground
	public Component getTableCellRendererComponent(JTable table, Object value,     
			boolean isSelected, boolean hasFocus, int row, int column) {     
		if (table != null) {     
		  JTableHeader header = table.getTableHeader();     
		  if (header != null) {     
		    rendererComponent.setForeground(header.getForeground());     
		    rendererComponent.setBackground(header.getBackground());     
		    rendererComponent.setFont(header.getFont());     
		    header.addMouseListener(rendererComponent);     
		  }      
		}      
 
		setColumn(column); //For enable the header check box     
		setHorizontalAlignment(SwingConstants.CENTER);
		return rendererComponent;     
	}      
	protected void setColumn(int column) {     
		this.column = column;     
	}      
	public int getColumn() {      
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getBackground, getFont, getForeground, getDefaultRenderer
 
        if (table != null) {
            JTableHeader header = table.getTableHeader();
            try { 
                if (header != null) {
                    TableCellRenderer tcr = header.getDefaultRenderer();
                    Component c = tcr.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
                    if (c instanceof JLabel) {
                        renderer = (JLabel) c;
                        renderer.setFont(header.getFont());
                        renderer.setBackground(header.getBackground());
                        renderer.setForeground(header.getForeground());
                    } 
                } 
            } catch (NullPointerException ignored) {
                // happens occasionally, ignore. 
            } 
        } 
 
        if (value instanceof Icon) {
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getBackground, getFont, getForeground
            button.getModel().setArmed(isPressed);
            component = button;
        } 
 
        if (header != null) {
            component.setForeground(header.getForeground());
            component.setBackground(header.getBackground());
            component.setFont(header.getFont());
        } 
        return component;
    } 
 
    /** 
     * Returns the correct button component. 
     * 
     * @param isSorting whether the render component represents the sort column. 
     * @param isAscending whether the model is ascending. 
     * @return either the ascending, descending or normal button. 
     */ 
    private JButton getRendererButton(final boolean isSorting, final boolean isAscending) {
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getBackground, getFont, getForeground
    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {
        if (table != null) {
            JTableHeader header = table.getTableHeader();
            if (header != null){
                setForeground(header.getForeground());
                setBackground(header.getBackground());
                setFont(header.getFont());
            } 
            setText(getText(value, row, column));
            setBorder(UIManager.getBorder("TableHeader.cellBorder"));
            setHorizontalAlignment(SwingConstants.CENTER);
        } 
        return this;
    } 
 
    /** 
     * Get the text for the value as the translation of the resource name. 
     * 
     * @param value 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setDefaultRenderer, setReorderingAllowed
        tableModel.setColumnHeadings(flkcLoad);
        tableModel.setRomHeadings(flkcRpm);
        tableModel.setFlkcData(flkcData);
        flkcTable = new JTable(tableModel);
        setTableBehaviour(flkcTable);
        flkcTablePanel.add(
                formatTableHeader(flkcTable),
                BorderLayout.PAGE_START);
        if (flkcData.size() > 0) {
            flkcTablePanel.add(flkcTable);
        } 
        else { 
            flkcTablePanel.add(new JLabel(
                    " No data - FLKC reference parameter ID not defined")); 
        } 
 
        flkcTitlePanel.add(flkcTablePanel, BorderLayout.CENTER);
        return flkcTitlePanel;
    } 
 

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getBackground, getFont, getForeground
      if (table != null)
      { 
         JTableHeader header = table.getTableHeader();
         if (header != null)
         { 
            setForeground(header.getForeground());
            setBackground(header.getBackground());
            setFont(header.getFont());
         } 
         setText(getText(value, row, column));
         setBorder(UIManager.getBorder("TableHeader.cellBorder"));
         setHorizontalAlignment(JLabel.CENTER);
      } 
      return this;
   } 
 
   @Override 
   protected String getText(Object value, int row, int column)
   { 
      if (value == null) 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getBackground, getFont, getForeground
    if (table != null)
    { 
      final JTableHeader header = table.getTableHeader();
      if (header != null)
      { 
        setForeground(header.getForeground());
        setBackground(header.getBackground());
        setFont(header.getFont());
      } 
    } 
 
    setText((value == null) ? "" : value.toString());
    setBorder(UIManager.getBorder("TableHeader.cellBorder"));
    return this;
  } 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
        table.setAutoCreateRowSorter(true);
        table.setGridColor(Color.GRAY);
        table.setShowGrid(true);
        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        table.setRowSelectionAllowed(true);
        table.setTableHeader(new JTableHeader(table.getColumnModel()));
        Util.setupColumnWidths(table.getColumnModel(), MAIN_COLS);
//        table.setFont(new Font("Monospaced", table.getFont().getStyle(), table.getFont().getSize())); 
        table.getSelectionModel().addListSelectionListener(new RequestListSelectionListener(this, table, screenSize));
 
        add(new JScrollPane(table));
 
        setTitle(file.getPath());
 
        // setup location and size and ensure updating preferences 
        Util.setupComponentLocationSize(this, MAIN_X, MAIN_Y, MAIN_WIDTH, MAIN_HEIGHT, (int) screenSize.getWidth() / 4,
                0, (int) screenSize.getWidth() / 2, (int) screenSize.getHeight() / 4);
 
        Util.disposeStartupDialog(text);
    } 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getColumnModel, getHeaderRect
    return point(tableHeader, checkIndexInBounds(tableHeader, index));
  } 
 
  @RunsInCurrentThread 
  private static @Nonnull Point point(@Nonnull JTableHeader tableHeader, int index) {
    Rectangle r = tableHeader.getHeaderRect(index);
    return new Point(r.x + r.width / 2, r.y + r.height / 2);
  } 
 
  @RunsInCurrentThread 
  private int checkIndexInBounds(@Nonnull JTableHeader tableHeader, int index) {
    int itemCount = columnCount(tableHeader);
    if (index >= 0 && index < itemCount) {
      return index;
    } 
    String msg = String.format("Item index <%d> should be between <0> and <%d>", index, itemCount - 1);
    throw new IndexOutOfBoundsException(msg);
  } 
 
  /** 

5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getDefaultRenderer, setReorderingAllowed, setResizingAllowed
	public static void initializeTable(JTable table)
	{ 
		table.setAutoCreateColumnsFromModel(false);
		JTableHeader header = table.getTableHeader();
		TableColumnModel columns = new DefaultTableColumnModel();
		TableCellRenderer headerRenderer = header.getDefaultRenderer();
		columns.addColumn(Utilities.createTableColumn(0, "in_level", headerRenderer, false));
		columns.addColumn(Utilities.createTableColumn(1, "in_class", headerRenderer, true));
		TableColumn remainCol = Utilities.createTableColumn(2, "in_iskRemain", headerRenderer, false);
		remainCol.setCellRenderer(new BoldNumberRenderer());
		columns.addColumn(remainCol);
		columns.addColumn(Utilities.createTableColumn(3, "in_gained", headerRenderer, false));
		table.setDefaultRenderer(Integer.class,
			new TableCellUtilities.AlignRenderer(SwingConstants.CENTER));
		table.setColumnModel(columns);
		table.setFocusable(false);
		header.setReorderingAllowed(false);
		header.setResizingAllowed(false);
	} 
 

5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
See Code Examples for Java 8 JTableHeader Methods: