Example usage for javax.swing LookAndFeel installColorsAndFont

List of usage examples for javax.swing LookAndFeel installColorsAndFont

Introduction

In this page you can find the example usage for javax.swing LookAndFeel installColorsAndFont.

Prototype

public static void installColorsAndFont(JComponent c, String defaultBgName, String defaultFgName,
        String defaultFontName) 

Source Link

Document

Convenience method for setting a component's foreground, background and font properties with values from the defaults.

Usage

From source file:RowNumberHeader.java

public RowNumberHeader(JTable table) {
    super();/* w w w  . java  2 s.  c om*/
    mainTable = table;
    setModel(new RowNumberTableModel());
    setPreferredScrollableViewportSize(getMinimumSize());
    setRowSelectionAllowed(false);
    JComponent renderer = (JComponent) getDefaultRenderer(Object.class);
    LookAndFeel.installColorsAndFont(renderer, "TableHeader.background", "TableHeader.foreground",
            "TableHeader.font");
    LookAndFeel.installBorder(this, "TableHeader.cellBorder");
}

From source file:SortedTableModel.java

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    Component text;//from  ww  w .j  a va  2s .c  om
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());

    if (textRenderer != null) {
        text = textRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    } else {
        text = new JLabel((String) value, JLabel.CENTER);
        LookAndFeel.installColorsAndFont((JComponent) text, "TableHeader.background", "TableHeader.foreground",
                "TableHeader.font");
    }
    panel.add(text, BorderLayout.CENTER);

    if (column == sortColumn) {
        BasicArrowButton bab = new BasicArrowButton(
                (sortAscending ? SwingConstants.NORTH : SwingConstants.SOUTH));
        panel.add(bab, BorderLayout.WEST);
    }
    LookAndFeel.installBorder(panel, "TableHeader.cellBorder");
    return panel;
}

From source file:SortedTableModel.java

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    JLabel label;//from  w  w  w .  j a  va2 s . c o  m
    removeAll();
    String[] header = ((String) value).split("\n");
    setLayout(new GridLayout(header.length, 1));
    for (String s : header) {
        label = new JLabel(s, JLabel.CENTER);
        LookAndFeel.installColorsAndFont(label, "TableHeader.background", "TableHeader.foreground",
                "TableHeader.font");
        add(label);
    }
    LookAndFeel.installBorder(this, "TableHeader.cellBorder");
    return this;
}

From source file:edu.ucla.stat.SOCR.chart.Chart.java

/**
 * setup GUI layout for the data panel including datatable and summary textArea
 *
 *///from   ww  w  .  jav a 2 s .  com
protected void initTable() {

    tModel = new DefaultTableModel(dataObject, columnNames);
    hModel = new DefaultTableModel(0, 1);

    dataTable = new JTable(tModel);
    /*   System.out.println("here");
       dataTable.getTableHeader().addMouseListener(new MouseAdapter(){  
           public void mouseClicked(MouseEvent e) {  
     TableColumnModel colModel = dataTable.getColumnModel();
       int columnModelIndex = colModel.getColumnIndexAtX(e.getX());
       selectedHeaderColumnIndex = colModel.getColumn(columnModelIndex)
           .getModelIndex();
               
        System.out.println("mouseClicked haeder "+selectedHeaderColumnIndex);
     }  
       });*/

    /*final JTableHeader heading = dataTable.getTableHeader();
    dataTable.addMouseListener(new MouseAdapter(){  
        public void mouseClicked(MouseEvent e) {  
           selectedHeaderColumnIndex = heading.columnAtPoint(e.getPoint());  
           System.out.println("mouseClicked haeder "+selectedHeaderColumnIndex);
        }  
     });  */
    dataTable.addKeyListener(this);
    dataTable.setGridColor(Color.gray);
    dataTable.setShowGrid(true);

    for (int i = 0; i < tModel.getRowCount(); i++)
        hModel.addRow(new Object[] { (i + 1) + ":" });

    headerTable = new JTable(hModel);

    headerTable.setCellSelectionEnabled(false);
    headerTable.setEnabled(false);
    headerTable.setGridColor(Color.gray);
    headerTable.setShowGrid(true);
    LookAndFeel.installColorsAndFont(headerTable, "TableHeader.background", "TableHeader.foreground",
            "TableHeader.font");
    headerTable.setIntercellSpacing(new Dimension(0, 0));
    Dimension d = headerTable.getPreferredScrollableViewportSize();
    d.width = headerTable.getPreferredSize().width;
    headerTable.setPreferredScrollableViewportSize(d);
    headerTable.setRowHeight(dataTable.getRowHeight());
    headerTable.setDefaultRenderer(Object.class, new RowHeaderRenderer());

    JTableHeader corner = headerTable.getTableHeader();
    corner.setReorderingAllowed(false);
    corner.setResizingAllowed(false);

    // this is a fix for the BAD SGI Java VM - not up to date as of dec. 22, 2003
    try {
        dataTable.setDragEnabled(true);
    } catch (Exception e) {
    }
    columnModel = dataTable.getColumnModel();
    dTableHeader = new EditableHeader(columnModel);
    dataTable.setTableHeader(dTableHeader);
    dataTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    dataTable.setCellSelectionEnabled(true);
    dataTable.setColumnSelectionAllowed(true);
    dataTable.setRowSelectionAllowed(true);

    hookTableAction();

    dataPanel = new JPanel();

    summaryPanel = new JTextArea();
    //      summaryPanel.setPreferredSize(new Dimension(CHART_SIZE_X,CHART_SIZE_Y/2));
    Color bg = dataPanel.getBackground();
    summaryPanel.setBackground(bg);
    summaryPanel.setEditable(false);
    summaryPanel.setForeground(Color.BLACK);

    dataPanel.setLayout(new BoxLayout(dataPanel, BoxLayout.Y_AXIS));
    JScrollPane tablePanel = new JScrollPane(dataTable);

    tablePanel.setRowHeaderView(headerTable);
    tablePanel.setCorner(JScrollPane.UPPER_LEFT_CORNER, corner);
    new JScrollPaneAdjuster(tablePanel);

    new JTableRowHeaderResizer(tablePanel).setEnabled(true);

    dataPanel.add(tablePanel);
    JScrollPane st = new JScrollPane(summaryPanel);
    st.setPreferredSize(new Dimension(CHART_SIZE_X, CHART_SIZE_Y / 3));
    dataPanel.add(new JScrollPane(st));

    dataPanel.validate();
}

From source file:edu.ucla.stat.SOCR.chart.Chart.java

/**
 * clear data panel/* w  w  w.  j  a v a2  s  .co  m*/
 *
 */
public void resetTable() {

    //   System.out.println("resetTable get called");
    for (int i = 0; i < columnNumber; i++)
        columnNames[i] = new String(DEFAULT_HEADER + (i + 1));

    tModel = new javax.swing.table.DefaultTableModel(dataObject, columnNames);
    hModel = new DefaultTableModel(0, 1);

    for (int i = 0; i < tModel.getRowCount(); i++)
        hModel.addRow(new Object[] { (i + 1) + ":" });

    dataTable = new JTable(tModel);
    /*   System.out.println("here2");
       dataTable.getTableHeader().addMouseListener(new MouseAdapter(){  
           public void mouseClicked(MouseEvent e) {  
     TableColumnModel colModel = dataTable.getColumnModel();
       int columnModelIndex = colModel.getColumnIndexAtX(e.getX());
       selectedHeaderColumnIndex = colModel.getColumn(columnModelIndex)
           .getModelIndex();
               
        System.out.println("mouseClicked haeder "+selectedHeaderColumnIndex);
     }  
       });*/
    /*final JTableHeader heading = dataTable.getTableHeader();
    heading.addMouseListener(new MouseAdapter(){  
        public void mouseClicked(MouseEvent e) {  
           selectedHeaderColumnIndex = heading.columnAtPoint(e.getPoint());  
           System.out.println("mouseClicked haeder "+selectedHeaderColumnIndex);
        }  
     });  */
    dataTable.setGridColor(Color.gray);
    dataTable.setShowGrid(true);
    dataTable.doLayout();
    dataTable.setCellSelectionEnabled(true);
    dataTable.setColumnSelectionAllowed(true);
    dataTable.setRowSelectionAllowed(true);

    columnModel = dataTable.getColumnModel();
    dTableHeader = new EditableHeader(columnModel);
    dataTable.setTableHeader(dTableHeader);

    listIndex = new int[dataTable.getColumnCount()];
    for (int j = 0; j < listIndex.length; j++)
        listIndex[j] = 1;

    hookTableAction();

    headerTable = new JTable(hModel);
    headerTable.setCellSelectionEnabled(false);
    LookAndFeel.installColorsAndFont(headerTable, "TableHeader.background", "TableHeader.foreground",
            "TableHeader.font");
    headerTable.setIntercellSpacing(new Dimension(0, 0));
    Dimension d = headerTable.getPreferredScrollableViewportSize();
    d.width = headerTable.getPreferredSize().width;
    headerTable.setPreferredScrollableViewportSize(d);
    headerTable.setRowHeight(dataTable.getRowHeight());
    headerTable.setDefaultRenderer(Object.class, new RowHeaderRenderer());
    JTableHeader corner = headerTable.getTableHeader();
    corner.setReorderingAllowed(false);
    corner.setResizingAllowed(false);

    //      summaryPanel.setPreferredSize(new Dimension(CHART_SIZE_X,CHART_SIZE_Y/2));
    summaryPanel.removeAll();

    dataPanel.removeAll();
    JScrollPane tablePanel = new JScrollPane(dataTable);
    tablePanel.setRowHeaderView(headerTable);
    tablePanel.setCorner(JScrollPane.UPPER_LEFT_CORNER, corner);
    new JScrollPaneAdjuster(tablePanel);
    new JTableRowHeaderResizer(tablePanel).setEnabled(true);
    dataPanel.add(tablePanel);

    JScrollPane st = new JScrollPane(summaryPanel);
    st.setPreferredSize(new Dimension(CHART_SIZE_X, CHART_SIZE_Y / 3));
    dataPanel.add(new JScrollPane(st));
    dataPanel.validate();

}