Search in sources :

Example 1 with Component

use of java.awt.Component in project hackpad by dropbox.

the class RunProxy method updateToolTip.

/**
     * Updates the tool tip contents.
     */
private void updateToolTip() {
    // Try to set tool tip on frame. On Mac OS X 10.5,
    // the number of components is different, so try to be safe.
    int n = getComponentCount() - 1;
    if (n > 1) {
        n = 1;
    } else if (n < 0) {
        return;
    }
    Component c = getComponent(n);
    // this will work at least for Metal L&F
    if (c != null && c instanceof JComponent) {
        ((JComponent) c).setToolTipText(getUrl());
    }
}
Also used : Component(java.awt.Component) MenuComponent(java.awt.MenuComponent) Point(java.awt.Point)

Example 2 with Component

use of java.awt.Component in project screenbird by adamhub.

the class RecorderPanel method showUploadMessage.

/*
     * Upload methods 
     */
/**
     * Displays a message on the upload form, formatted with a text color.
     * @param message
     * @param type 
     */
public void showUploadMessage(String message, Color type) {
    int start = 0;
    int end = 0;
    Component focusedComponent = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    if (focusedComponent instanceof JTextComponent) {
        end = ((JTextComponent) focusedComponent).getSelectionEnd();
        start = ((JTextComponent) focusedComponent).getSelectionStart();
    }
    Dimension size = new Dimension(160, 14);
    this.lblUploadMessage.setPreferredSize(size);
    this.lblUploadMessage.setMinimumSize(size);
    this.lblUploadMessage.setMaximumSize(size);
    this.lblUploadMessage.setSize(size);
    this.pbEncoding.setVisible(true);
    this.pbEncoding.setForeground(type);
    this.lblUploadMessage.validate();
    this.lblUploadMessage.setText(message);
    this.lblUploadMessage.setVisible(true);
    this.lblUploadMessage.setForeground(type);
    ((JFrame) this.getParent().getParent().getParent().getParent()).pack();
    this.redrawWindow();
    if (focusedComponent instanceof JTextComponent) {
        ((JTextComponent) focusedComponent).grabFocus();
        ((JTextComponent) focusedComponent).setSelectionStart(start);
        ((JTextComponent) focusedComponent).setSelectionEnd(end);
    }
}
Also used : JFrame(javax.swing.JFrame) JTextComponent(javax.swing.text.JTextComponent) Dimension(java.awt.Dimension) Component(java.awt.Component) JTextComponent(javax.swing.text.JTextComponent)

Example 3 with Component

use of java.awt.Component in project druid by alibaba.

the class ColumnGroup method getSize.

/**
     * 取得合并后的单元格的大小,这个方法需要计算,首先 是取得一个没有合并的最小单元格的JTableHeader 的大小
     * 通过Renderer取得组件
     * 
     * @return
     */
public Dimension getSize(JTable table) {
    Component comp = renderer.getTableCellRendererComponent(table, getHeaderValue(), false, false, -1, -1);
    int height = comp.getPreferredSize().height;
    int width = 0;
    // 宽度需要计算合并的还要加上间隙
    Enumeration<Object> enumeration = vector.elements();
    while (enumeration.hasMoreElements()) {
        Object obj = enumeration.nextElement();
        if (obj instanceof TableColumn) {
            TableColumn aColumn = (TableColumn) obj;
            width += aColumn.getWidth();
            width += margin;
        } else {
            width += ((ColumnGroup) obj).getSize(table).width;
        }
    }
    return new Dimension(width, height);
}
Also used : Dimension(java.awt.Dimension) Component(java.awt.Component) TableColumn(javax.swing.table.TableColumn)

Example 4 with Component

use of java.awt.Component in project druid by alibaba.

the class GroupableTableHeaderUI method paintCell.

private void paintCell(Graphics g, Rectangle cellRect, ColumnGroup cGroup) {
    TableCellRenderer renderer = cGroup.getHeaderRenderer();
    //
    if (renderer == null) {
        renderer = new DefaultTableCellRenderer() {

            private static final long serialVersionUID = 1L;

            @Override
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                JTableHeader header = table.getTableHeader();
                if (header != null) {
                    setForeground(header.getForeground());
                    setBackground(header.getBackground());
                    setFont(header.getFont());
                }
                setHorizontalAlignment(JLabel.CENTER);
                setText((value == null) ? "" : value.toString());
                setBorder(UIManager.getBorder("TableHeader.cellBorder"));
                return this;
            }
        };
    }
    String headerValue = cGroup.getHeaderValue().toString();
    Component component = renderer.getTableCellRendererComponent(header.getTable(), headerValue, false, false, -1, -1);
    rendererPane.add(component);
    rendererPane.paintComponent(g, component, header, cellRect.x, cellRect.y, cellRect.width, cellRect.height, true);
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) JTable(javax.swing.JTable) JTableHeader(javax.swing.table.JTableHeader) JComponent(javax.swing.JComponent) Component(java.awt.Component) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer)

Example 5 with Component

use of java.awt.Component in project druid by alibaba.

the class GroupableTableHeaderUI method paintCell.

private void paintCell(Graphics g, Rectangle cellRect, int columnIndex) {
    TableColumn aColumn = header.getColumnModel().getColumn(columnIndex);
    TableCellRenderer renderer = aColumn.getHeaderRenderer();
    //
    if (renderer == null) {
        renderer = new DefaultTableCellRenderer() {

            private static final long serialVersionUID = 1L;

            @Override
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                JTableHeader header = table.getTableHeader();
                if (header != null) {
                    setForeground(header.getForeground());
                    setBackground(header.getBackground());
                    setFont(header.getFont());
                }
                setHorizontalAlignment(JLabel.CENTER);
                setText((value == null) ? "" : value.toString());
                setBorder(UIManager.getBorder("TableHeader.cellBorder"));
                return this;
            }
        };
    }
    String headerValue = aColumn.getHeaderValue().toString();
    Component component = renderer.getTableCellRendererComponent(header.getTable(), headerValue, false, false, -1, columnIndex);
    rendererPane.add(component);
    rendererPane.paintComponent(g, component, header, cellRect.x, cellRect.y, cellRect.width, cellRect.height, true);
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) JTable(javax.swing.JTable) JTableHeader(javax.swing.table.JTableHeader) JComponent(javax.swing.JComponent) Component(java.awt.Component) TableColumn(javax.swing.table.TableColumn) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer)

Aggregations

Component (java.awt.Component)443 JComponent (javax.swing.JComponent)93 Dimension (java.awt.Dimension)47 Point (java.awt.Point)43 Insets (java.awt.Insets)35 JLabel (javax.swing.JLabel)35 TableCellRenderer (javax.swing.table.TableCellRenderer)29 JPanel (javax.swing.JPanel)28 Color (java.awt.Color)25 Container (java.awt.Container)25 JButton (javax.swing.JButton)24 JTextComponent (javax.swing.text.JTextComponent)21 TableColumn (javax.swing.table.TableColumn)20 JMenuItem (javax.swing.JMenuItem)19 GridBagConstraints (java.awt.GridBagConstraints)17 GridBagLayout (java.awt.GridBagLayout)17 JPopupMenu (javax.swing.JPopupMenu)17 BorderLayout (java.awt.BorderLayout)16 JScrollPane (javax.swing.JScrollPane)16 Rectangle (java.awt.Rectangle)14