Search in sources :

Example 36 with DefaultTableCellRenderer

use of javax.swing.table.DefaultTableCellRenderer in project specify by rhebecaabreu.

the class MeusProjetos method criaTableShowD.

public void criaTableShowD(JPanel panel) {
    table = new JTable();
    table.setCellSelectionEnabled(true);
    table.setGridColor(SystemColor.controlHighlight);
    // table_3.setBounds(3, 24, 540, 0);
    table.setFont(new Font("Lucida Sans Unicode", Font.PLAIN, 13));
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    // table_3.setTableHeader(null);
    table.getTableHeader().setResizingAllowed(true);
    table.getTableHeader().setReorderingAllowed(false);
    JTableHeader header = table.getTableHeader();
    DefaultTableCellRenderer centralizado = (DefaultTableCellRenderer) header.getDefaultRenderer();
    centralizado.setHorizontalAlignment(SwingConstants.CENTER);
    table.setModel(showr);
    table.getColumnModel().getColumn(0).setPreferredWidth(536);
    TableColumn col = table.getColumnModel().getColumn(0);
    col.setCellRenderer(new TextAreaCellRenderer());
    JTableHeader cabecalho = table.getTableHeader();
    cabecalho.setFont(new Font("Leelawadee UI", Font.PLAIN, 12));
    panel.add(table);
    scrollPane3 = new JScrollPane(table);
    scrollPane3.setBounds(4, 10, 559, 440);
    // só mostra a barra vertical se necessário
    scrollPane3.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    // só mostra a barra horizontal se necessário
    scrollPane3.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    panel.add(scrollPane3);
}
Also used : JScrollPane(javax.swing.JScrollPane) JTable(javax.swing.JTable) JTableHeader(javax.swing.table.JTableHeader) TableColumn(javax.swing.table.TableColumn) Font(java.awt.Font) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer)

Example 37 with DefaultTableCellRenderer

use of javax.swing.table.DefaultTableCellRenderer in project specify by rhebecaabreu.

the class MeusProjetos method criaJTable.

public void criaJTable() {
    table_1 = new JTable();
    table_1.setShowVerticalLines(true);
    table_1.setShowHorizontalLines(true);
    table_1.setGridColor(SystemColor.scrollbar);
    table_1.setSelectionBackground(SystemColor.textHighlight);
    table_1.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    table_1.setBounds(3, 24, 540, 0);
    table_1.setFont(new Font("Leelawadee UI", Font.PLAIN, 12));
    table_1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table_1.getTableHeader().setResizingAllowed(true);
    table_1.getTableHeader().setReorderingAllowed(false);
    table_1.setBorder(new MatteBorder(1, 1, 1, 1, (Color) UIManager.getColor("Menu[Disabled].textForeground")));
    table_1.setModel(tableModel);
    table_1.getColumnModel().getColumn(0).setPreferredWidth(18);
    table_1.getColumnModel().getColumn(1).setPreferredWidth(50);
    table_1.getColumnModel().getColumn(2).setPreferredWidth(169);
    table_1.getColumnModel().getColumn(3).setPreferredWidth(110);
    table_1.getColumnModel().getColumn(4).setPreferredWidth(140);
    table_1.getColumnModel().getColumn(5).setPreferredWidth(185);
    JTableHeader cabecalho = table_1.getTableHeader();
    cabecalho.setFont(new Font("Leelawadee UI", Font.PLAIN, 12));
    DefaultTableCellRenderer esquerda = new DefaultTableCellRenderer();
    DefaultTableCellRenderer centro = new DefaultTableCellRenderer();
    DefaultTableCellRenderer direita = new DefaultTableCellRenderer();
    esquerda.setHorizontalAlignment(SwingConstants.LEFT);
    centro.setHorizontalAlignment(SwingConstants.CENTER);
    direita.setHorizontalAlignment(SwingConstants.RIGHT);
    table_1.getColumnModel().getColumn(3).setCellRenderer(centro);
    table_1.getColumnModel().getColumn(4).setCellRenderer(centro);
    table_1.getColumnModel().getColumn(0).setCellRenderer(centro);
    table_1.getColumnModel().getColumn(1).setCellRenderer(centro);
    AbtToolTipHeader tooltipHeader = new AbtToolTipHeader(table_1.getColumnModel());
    // Seta a table header de tooltips
    table_1.setTableHeader(tooltipHeader);
    tooltipHeader.addToolTipToColumn(// Coluna 0
    1, "Código do requisito");
    tooltipHeader.addToolTipToColumn(// Coluna 0
    2, "Identificador do requisito");
    tooltipHeader.addToolTipToColumn(// Coluna 0
    3, "Tipo de requisito");
    tooltipHeader.addToolTipToColumn(// Coluna 0
    4, "Data da criação/inclusão do requisito no sistema");
    tooltipHeader.addToolTipToColumn(// Coluna 0
    5, "Última modificação/alteração realizada no requisito");
    TableColumn tc = table_1.getColumnModel().getColumn(0);
    tc.setCellEditor(table_1.getDefaultEditor(Boolean.class));
    tc.setCellRenderer(table_1.getDefaultRenderer(Boolean.class));
    table_1.setRowHeight(20);
    tc.setHeaderRenderer(new PhDCheckHeader(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            // ações quando clicar no check
            Object source = e.getSource();
            if (source instanceof AbstractButton == false) {
                return;
            }
            boolean check = e.getStateChange() == ItemEvent.SELECTED;
            int coluna = 0;
            if (check == true) {
                for (int i = 0; i < table_1.getRowCount(); i++) {
                    table_1.setValueAt(new Boolean(check), i, coluna);
                    table_1.addRowSelectionInterval(i, i);
                }
            } else {
                for (int i = 0; i < table_1.getRowCount(); i++) {
                    table_1.setValueAt(new Boolean(check), i, coluna);
                    table_1.removeRowSelectionInterval(i, i);
                }
            }
        }
    }));
    ((DefaultTableCellRenderer) table_1.getTableHeader().getDefaultRenderer()).setHorizontalAlignment(SwingConstants.CENTER);
    panelRequisitos.setLayout(null);
    panelRequisitos.add(table_1);
    scrollPane2 = new JScrollPane(table_1);
    scrollPane2.setBounds(4, 29, 570, 498);
    // só mostra a barra vertical se necessário
    scrollPane2.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    // só mostra a barra horizontal se necessário
    scrollPane2.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    panelRequisitos.add(scrollPane2);
}
Also used : JScrollPane(javax.swing.JScrollPane) ItemEvent(java.awt.event.ItemEvent) AbstractButton(javax.swing.AbstractButton) Color(java.awt.Color) SystemColor(java.awt.SystemColor) JTableHeader(javax.swing.table.JTableHeader) TableColumn(javax.swing.table.TableColumn) Font(java.awt.Font) Point(java.awt.Point) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) MatteBorder(javax.swing.border.MatteBorder) JTable(javax.swing.JTable) ItemListener(java.awt.event.ItemListener)

Example 38 with DefaultTableCellRenderer

use of javax.swing.table.DefaultTableCellRenderer in project 2XB3 by SurayaAtouraya.

the class MainMenu method initialize.

// Initialize the contents of the main frame.
private void initialize() throws IOException {
    frame.addWindowListener(CloseWindow);
    frame.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
    newFrame.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    JButton find = new JButton("Find Contractor");
    JButton end = new JButton("Exit Program");
    end.addActionListener(CloseFrame);
    find.addActionListener(FindButton);
    pane.add(find);
    pane.add(end);
    model.addColumn("Contractor Name");
    model.addColumn("License Number");
    model.addColumn("State");
    model.addColumn("City");
    model.addColumn("Address");
    model.addColumn("Phone Number");
    model.addColumn("Speciality");
    model.addColumn("Rating");
    DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
    centerRenderer.setHorizontalAlignment(JLabel.CENTER);
    for (int i = 0; i <= 7; i++) {
        contractorTable.getColumnModel().getColumn(i).setCellRenderer(centerRenderer);
    }
    contractorTable.getColumnModel().getColumn(0).setPreferredWidth(150);
    contractorTable.getColumnModel().getColumn(1).setPreferredWidth(75);
    contractorTable.getColumnModel().getColumn(2).setPreferredWidth(0);
    contractorTable.getColumnModel().getColumn(3).setPreferredWidth(100);
    contractorTable.getColumnModel().getColumn(4).setPreferredWidth(150);
    contractorTable.getColumnModel().getColumn(5).setPreferredWidth(100);
    contractorTable.getColumnModel().getColumn(6).setPreferredWidth(200);
    contractorTable.getColumnModel().getColumn(7).setPreferredWidth(0);
    contractorTable.getTableHeader().setReorderingAllowed(false);
    contractorTable.getTableHeader().setResizingAllowed(false);
    contractorTable.isCellEditable(0, 0);
    JScrollPane scrollPane = new JScrollPane(contractorTable);
    scrollPane.setPreferredSize(new Dimension(1300, 650));
    pane.add(scrollPane);
    frame.add(pane);
    frame.setVisible(true);
}
Also used : JScrollPane(javax.swing.JScrollPane) JButton(javax.swing.JButton) Dimension(java.awt.Dimension) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer)

Example 39 with DefaultTableCellRenderer

use of javax.swing.table.DefaultTableCellRenderer in project WorldPainter by Captain-Chaos.

the class SimpleThemeEditor method setTheme.

public void setTheme(SimpleTheme theme) {
    this.theme = theme;
    if (theme != null) {
        terrainTableModel = new TerrainRangesTableModel(theme.getTerrainRanges());
        terrainTableModel.setChangeListener(this);
        tableTerrain.setModel(terrainTableModel);
        tableTerrain.setDefaultRenderer(Integer.class, new DefaultTableCellRenderer());
        tableTerrain.setDefaultRenderer(Terrain.class, new TerrainTableCellRenderer(colourScheme));
        tableTerrain.setDefaultRenderer(JButton.class, new JButtonTableCellRenderer());
        tableTerrain.setDefaultEditor(Integer.class, new JSpinnerTableCellEditor(new SpinnerNumberModel(1, 1, theme.getMaxHeight() - 1, 1)));
        JComboBox terrainEditor = new JComboBox(Terrain.getConfiguredValues());
        terrainEditor.setRenderer(new TerrainListCellRenderer(colourScheme));
        tableTerrain.setDefaultEditor(Terrain.class, new DefaultCellEditor(terrainEditor));
        tableTerrain.setDefaultEditor(JButton.class, new JButtonTableCellEditor(this));
        checkBoxBeaches.setSelected(theme.isBeaches());
        spinnerWaterLevel.setModel(new SpinnerNumberModel(theme.getWaterHeight(), 0, theme.getMaxHeight() - 1, 1));
        spinnerWaterLevel.setEnabled(checkBoxBeaches.isSelected());
        checkBoxRandomise.setSelected(theme.isRandomise());
        layerTableModel = new LayerRangesTableModel(theme.getMaxHeight(), theme.getLayerMap());
        tableLayers.setModel(layerTableModel);
        tableLayers.setDefaultRenderer(Layer.class, new LayerTableCellRenderer());
        tableLayers.setDefaultRenderer(JButton.class, new JButtonTableCellRenderer());
        tableLayers.setDefaultEditor(Integer.class, new JSpinnerTableCellEditor(new SpinnerNumberModel(1, 1, theme.getMaxHeight() - 1, 1)));
        tableLayers.setDefaultEditor(JButton.class, new JButtonTableCellEditor(this));
    }
}
Also used : SpinnerNumberModel(javax.swing.SpinnerNumberModel) JComboBox(javax.swing.JComboBox) JButtonTableCellRenderer(org.pepsoft.worldpainter.themes.JButtonTableCellRenderer) JButtonTableCellEditor(org.pepsoft.worldpainter.themes.JButtonTableCellEditor) TerrainTableCellRenderer(org.pepsoft.worldpainter.themes.TerrainTableCellRenderer) LayerTableCellRenderer(org.pepsoft.worldpainter.layers.LayerTableCellRenderer) JSpinnerTableCellEditor(org.pepsoft.worldpainter.themes.JSpinnerTableCellEditor) TerrainListCellRenderer(org.pepsoft.worldpainter.themes.TerrainListCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) DefaultCellEditor(javax.swing.DefaultCellEditor)

Example 40 with DefaultTableCellRenderer

use of javax.swing.table.DefaultTableCellRenderer in project com.revolsys.open by revolsys.

the class BaseColumnFactory method calcHeaderWidth.

@Override
protected int calcHeaderWidth(final JXTable table, final TableColumnExt tableColumn) {
    int width = super.calcHeaderWidth(table, tableColumn);
    width += this.sortWidth;
    final TableCellRenderer renderer = getHeaderRenderer(table, tableColumn);
    if (renderer instanceof DefaultTableCellRenderer) {
        final DefaultTableCellRenderer defaultTableCellRenderer = (DefaultTableCellRenderer) renderer;
        final int position = defaultTableCellRenderer.getHorizontalTextPosition();
        if (position > 0) {
            width += position;
        }
    }
    return width;
}
Also used : DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer)

Aggregations

DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)89 JTable (javax.swing.JTable)31 TableColumn (javax.swing.table.TableColumn)28 Component (java.awt.Component)21 JScrollPane (javax.swing.JScrollPane)20 DefaultTableModel (javax.swing.table.DefaultTableModel)18 TableCellRenderer (javax.swing.table.TableCellRenderer)17 MouseEvent (java.awt.event.MouseEvent)14 JLabel (javax.swing.JLabel)14 JComponent (javax.swing.JComponent)12 JTableHeader (javax.swing.table.JTableHeader)12 Dimension (java.awt.Dimension)11 Font (java.awt.Font)11 Color (java.awt.Color)10 GridBagConstraints (java.awt.GridBagConstraints)10 Insets (java.awt.Insets)10 BorderLayout (java.awt.BorderLayout)9 JPanel (javax.swing.JPanel)9 MouseAdapter (java.awt.event.MouseAdapter)8 GridBagLayout (java.awt.GridBagLayout)7