Example usage for javax.swing UIManager getBorder

List of usage examples for javax.swing UIManager getBorder

Introduction

In this page you can find the example usage for javax.swing UIManager getBorder.

Prototype

public static Border getBorder(Object key) 

Source Link

Document

Returns a border from the defaults.

Usage

From source file:MainClass.java

public static void main(String args[]) {
    String rows[][] = { { "A", "a" }, { "B", "b" }, { "E", "e" } };
    String headers[] = { "Upper", "Lower" };

    JFrame frame = new JFrame("Label Header");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTable table = new JTable(rows, headers);
    JScrollPane scrollPane = new JScrollPane(table);

    Border headerBorder = UIManager.getBorder("TableHeader.cellBorder");

    JLabel headerLabel1 = new JLabel(headers[0], JLabel.CENTER);
    headerLabel1.setBorder(headerBorder);
    JLabel headerLabel2 = new JLabel(headers[1], JLabel.CENTER);
    headerLabel2.setBorder(headerBorder);

    TableCellRenderer renderer = new JComponentTableCellRenderer();

    TableColumnModel columnModel = table.getColumnModel();

    TableColumn column0 = columnModel.getColumn(0);
    TableColumn column1 = columnModel.getColumn(1);

    column0.setHeaderRenderer(renderer);
    column0.setHeaderValue(headerLabel1);

    column1.setHeaderRenderer(renderer);
    column1.setHeaderValue(headerLabel2);

    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);/*from  ww w. ja  va 2  s.co m*/
    frame.setVisible(true);
}

From source file:JComponentTableCellRenderer.java

public static void main(String args[]) {
    final Object rows[][] = { { "one", "1" }, { "two", "2" }, { "three", "3" } };
    JFrame frame = new JFrame("Label Header");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    String headers[] = { "English", "#" };
    JTable table = new JTable(rows, headers);
    JScrollPane scrollPane = new JScrollPane(table);

    Icon redIcon = new ImageIcon("yourFile.gif");
    Icon blueIcon = new ImageIcon("yourFile.gif");

    Border headerBorder = UIManager.getBorder("TableHeader.cellBorder");

    JLabel blueLabel = new JLabel(headers[0], blueIcon, JLabel.CENTER);
    blueLabel.setBorder(headerBorder);/*from w w w  .  j  a va2s  . co  m*/
    JLabel redLabel = new JLabel(headers[1], redIcon, JLabel.CENTER);
    redLabel.setBorder(headerBorder);

    TableCellRenderer renderer = new JComponentTableCellRenderer();

    TableColumnModel columnModel = table.getColumnModel();

    TableColumn column0 = columnModel.getColumn(0);
    TableColumn column1 = columnModel.getColumn(1);

    column0.setHeaderRenderer(renderer);
    column0.setHeaderValue(blueLabel);

    column1.setHeaderRenderer(renderer);
    column1.setHeaderValue(redLabel);

    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:LabelHeaderSample.java

public static void main(String args[]) {
    Object rows[][] = { { "one", "ichi - \u4E00" }, { "two", "ni - \u4E8C" }, { "three", "san - \u4E09" },
            { "four", "shi - \u56DB" }, { "five", "go - \u4E94" }, { "six", "roku - \u516D" },
            { "seven", "shichi - \u4E03" }, { "eight", "hachi - \u516B" }, { "nine", "kyu - \u4E5D" },
            { "ten", "ju - \u5341" } };
    JFrame frame = new JFrame("Label Header");
    String headers[] = { "English", "Japanese" };
    JTable table = new JTable(rows, headers);
    JScrollPane scrollPane = new JScrollPane(table);

    Icon redIcon = new DiamondIcon(Color.red);
    Icon blueIcon = new DiamondIcon(Color.blue);

    Border headerBorder = UIManager.getBorder("TableHeader.cellBorder");

    JLabel blueLabel = new JLabel(headers[0], blueIcon, JLabel.CENTER);
    blueLabel.setBorder(headerBorder);/*from   ww w .  ja v a 2  s  . c o m*/
    JLabel redLabel = new JLabel(headers[1], redIcon, JLabel.CENTER);
    redLabel.setBorder(headerBorder);

    TableCellRenderer renderer = new JComponentTableCellRenderer();

    TableColumnModel columnModel = table.getColumnModel();

    TableColumn column0 = columnModel.getColumn(0);
    TableColumn column1 = columnModel.getColumn(1);

    column0.setHeaderRenderer(renderer);
    column0.setHeaderValue(blueLabel);

    column1.setHeaderRenderer(renderer);
    column1.setHeaderValue(redLabel);

    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:Main.java

public static Border getNativeLoweredBorder() {
    Border border = UIManager.getBorder("InsetBorder.aquaVariant");
    if (border == null)
        border = BorderFactory.createLoweredBevelBorder();
    return border;
}

From source file:MainClass.java

protected void configureEnclosingScrollPane() {
    Container container = getParent();
    if (container instanceof JViewport) {
        Container viewParent = container.getParent();
        if (viewParent instanceof JScrollPane) {
            JScrollPane scrollPane = (JScrollPane) viewParent;
            JViewport viewport = scrollPane.getViewport();
            if (viewport == null || viewport.getView() != this) {
                return;
            }//from   ww  w.  ja va  2s  .co  m
            scrollPane.setBorder(UIManager.getBorder("Table.scrollPaneBorder"));
        }
    }
}

From source file:Main.java

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());/* w w w.ja  v  a2s.co m*/
        }
    }

    if (value instanceof Icon) {
        setIcon((Icon) value);
        setText("");
    } else {
        setText((value == null) ? "" : value.toString());
        setIcon(null);
    }
    setBorder(UIManager.getBorder("TableHeader.cellBorder"));
    setHorizontalAlignment(JLabel.CENTER);
    return this;
}

From source file:Main.java

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());//from ww w . ja v a2 s  .co  m
        }
    }
    if (value instanceof TextAndIcon) {
        setIcon(((TextAndIcon) value).icon);
        setText(((TextAndIcon) value).text);
    } else {
        setText((value == null) ? "" : value.toString());
        setIcon(null);
    }
    setBorder(UIManager.getBorder("TableHeader.cellBorder"));
    setHorizontalAlignment(JLabel.CENTER);
    return this;
}

From source file:Main.java

public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
        boolean cellHasFocus) {
    setText(value.toString());//from  w  w  w.  ja v  a 2  s.  c o m

    setBackground(isSelected ? list.getSelectionBackground() : list.getBackground());
    setForeground(isSelected ? list.getSelectionForeground() : list.getForeground());

    setFont(list.getFont());
    setBorder((cellHasFocus) ? UIManager.getBorder("List.focusCellHighlightBorder") : m_noFocusBorder);

    return this;
}

From source file:Main.java

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    if (isSelected) {
        setBackground(UIManager.getColor("Table.selectionBackground"));
    }/*from w  w  w.j  a va2  s. c o  m*/

    if (hasFocus) {
        setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));

        if (table.isCellEditable(row, column)) {
            super.setForeground(UIManager.getColor("Table.focusCellForeground"));
            super.setBackground(UIManager.getColor("Table.focusCellBackground"));
        }
    } else {
        setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
    }
    setText((String) (value));
    table.setRowHeight(row, getPreferredSize().height + row * 10);
    return this;
}

From source file:ExtendedTableCellRenderer.java

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    if (isSelected) {
        super.setForeground(table.getSelectionForeground());
        super.setBackground(table.getSelectionBackground());

    } else {/*from  w w w  .j a  v  a 2  s  .c  om*/
        super.setForeground((unselectedForeground != null) ? unselectedForeground : table.getForeground());
        super.setBackground((unselectedBackground != null) ? unselectedBackground : table.getBackground());
    }

    setFont(table.getFont());

    if (hasFocus) {
        setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
        if (table.isCellEditable(row, column)) {
            super.setForeground(UIManager.getColor("Table.focusCellForeground"));
            super.setBackground(UIManager.getColor("Table.focusCellBackground"));
        }
    } else {
        setBorder(NO_FOCUS_BORDER);
    }

    setValue(value);

    Color background = getBackground();
    boolean colorMatch = (background != null) && (background.equals(table.getBackground())) && table.isOpaque();
    setOpaque(!colorMatch);

    return this;
}