Package javax.swing

Examples of javax.swing.ListCellRenderer


    public String getText() {
        return text;
    }

    public MComponent getRenderer() {
        ListCellRenderer renderer = (ListCellRenderer) eventQueueRunner.invoke(getListComponent(), "getCellRenderer");
        boolean isSelected = isSelected();
        ListModel listModel = (ListModel) eventQueueRunner.invoke(getListComponent(), "getModel");
        Component rendererComponent = renderer.getListCellRendererComponent(getListComponent(), listModel.getElementAt(index),
                index, isSelected, isSelected);
        MComponent mcomponent = rendererComponent == null ? null : finder.getMComponentByComponent(rendererComponent,
                getMComponentName() + "," + index, null);
        return mcomponent;
    }
View Full Code Here


            return null;
        return getStringRep(selectedItem);
    }

    private String getStringRep(final Object selectedItem) {
        final ListCellRenderer listCellRenderer = (ListCellRenderer) eventQueueRunner.invoke(getComboBox(), "getRenderer");
        if (listCellRenderer != null) {
            if (SwingUtilities.isEventDispatchThread()) {
                Component rendererComponent = listCellRenderer.getListCellRendererComponent(new JList(), selectedItem, 0, false,
                        false);
                if (rendererComponent != null) {
                    MComponent mcomp = finder.getMComponentByComponent(rendererComponent, "doesn't matter", null);
                    if (mcomp != null && !mcomp.getClass().equals(MComponent.class) && mcomp.getText() != null)
                        return stripHTMLTags(mcomp.getText());
                }
            } else {
                final Object[] r = new Object[1];
                r[0] = null;
                try {
                    SwingUtilities.invokeAndWait(new Runnable() {
                        public void run() {
                            Component rendererComponent = listCellRenderer.getListCellRendererComponent(new JList(), selectedItem,
                                    0, false, false);
                            if (rendererComponent != null) {
                                MComponent mcomp = finder.getMComponentByComponent(rendererComponent, "doesn't matter", null);
                                if (mcomp != null && !mcomp.getClass().equals(MComponent.class) && mcomp.getText() != null)
                                    r[0] = mcomp.getText();
View Full Code Here

    public MComponent getRendererAt(int index) {
        if (finder == null) {
            return null;
        }
        ListCellRenderer renderer = (ListCellRenderer) eventQueueRunner.invoke(getList(), "getCellRenderer");
        if (renderer == null)
            return null ;
        boolean isSelected = eventQueueRunner.invokeBoolean(getList(), "isSelectedIndex", new Object[] { Integer.valueOf(index) },
                new Class[] { Integer.TYPE });
        ListModel model = getModel();
        Component rendererComponent = renderer.getListCellRendererComponent(getList(), model.getElementAt(index), index,
                isSelected, isSelected);
        return (rendererComponent == null ? null : finder.getMComponentByComponent(rendererComponent, "doesn't matter", null));
    }
View Full Code Here

 
  private JComboBox makeComboBox(String name, Collection<?> items) {
    JComboBox box = new JComboBox (items.toArray());
    box.setName(name);
   
    box.setRenderer(new ListCellRenderer() {
      @Override
      public Component getListCellRendererComponent(JList list,
          Object obj, int arg2, boolean arg3, boolean arg4) {   
        if (obj instanceof Color) {
          return new StandardComboBoxColors.ColorPanel((Color) obj);
View Full Code Here

   */
  private JComboBox makeComboBox(String name, Collection<?> items) {
    JComboBox box = new JComboBox (items.toArray());
    box.setName(name);
   
    box.setRenderer(new ListCellRenderer() {
      @Override
      public Component getListCellRendererComponent(JList list,
          Object obj, int arg2, boolean arg3, boolean arg4) {   
        if (obj instanceof Shapereturn new ShapePanel((Shape) obj);
        if (obj instanceof Colorreturn new ColorPanel((Color) obj);
View Full Code Here

        panelTitleFontColorComboBox.setPreferredSize(new Dimension(50, 20));
        panelTitleFontColorComboBox.setSelectedIndex(0);

//        BackgroundColorComboBoxRenderer renderer = new BackgroundColorComboBoxRenderer();
       
        panelTitleFontColorComboBox.setRenderer(new ListCellRenderer() {
           
            private ColorPanel myColorPanel = new ColorPanel(new Color(0));
           
            @Override
            public Component getListCellRendererComponent(JList list,
                    Object obj, int arg2, boolean arg3, boolean arg4) {
               
                if (obj instanceof Color) {
                    myColorPanel.setColor((Color) obj);
                    return myColorPanel;
                }
                return new JPanel();
            }
                       
        });
       
        // Attach listener to show foreground colors in combo box.
        panelTitleFontColorComboBox.addActionListener(new ActionListener() {
           
            @Override
            public void actionPerformed(ActionEvent e) {
                if (listenersEnabled) {
                    List<Panel> selectedPanels = managedCanvas.getSelectedPanels();
                    CanvasFormattingController.notifyTitleBarFontForegroundColorSelected(
                                    Integer.valueOf((Color.class.cast(panelTitleFontColorComboBox.getSelectedItem())).getRGB()),
                                                    selectedPanels);
                    managedCanvas.fireFocusPersist();
                }
            }
        });
       
        panelTitleFontStyleBold.addActionListener(panelTitleFontStyleListener);
        panelTitleFontStyleItalic.addActionListener(panelTitleFontStyleListener);
       
        panelTitleBackgroundColorComboBox = new JComboBox(ControlAreaFormattingConstants.BorderColors);
        panelTitleBackgroundColorComboBox.setName("Background_colorComboBox");
        panelTitleBackgroundColorComboBox.getAccessibleContext().setAccessibleName("panelTitleBackgroundColorComboBox");
        panelTitleBackgroundColorComboBox.setToolTipText("Background color");
        panelTitleBackgroundColorComboBox.setMaximumRowCount(5);
        panelTitleBackgroundColorComboBox.setPreferredSize(new Dimension(50, 20));
        panelTitleBackgroundColorComboBox.setSelectedIndex(0);

//        renderer = new BackgroundColorComboBoxRenderer();
       
        panelTitleBackgroundColorComboBox.setRenderer(new ListCellRenderer() {
           
            private ColorPanel myColorPanel = new ColorPanel(new Color(0));
           
            @Override
            public Component getListCellRendererComponent(JList list,
View Full Code Here

    table.getTableHeader().setDefaultRenderer(headerRenderer);
   
    rowHeaders = new JList(model.getRowLabelModel());
    rowHeaders.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
   
    rowHeaders.setCellRenderer(new ListCellRenderer() {

      @Override
      public Component getListCellRendererComponent(JList list,
          Object value, int index, boolean isSelected,
          boolean hasFocus) {
        JLabel label = (JLabel) defaultHeaderRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, 0, index);
        ContentAlignment alignment = LabeledTable.this.getRowHeaderAlignment(index);
        label.setHorizontalAlignment(alignment.getComponentAlignment());
        Border padding = BorderFactory.createEmptyBorder(0, 5, 0, 5);
        if (headerBorder != null) label.setBorder(headerBorder);
        label.setBorder(BorderFactory.createCompoundBorder(label.getBorder(), padding));
        Font headerFont = new Font(LabeledTable.this.getRowHeaderFontName(index).name(),
            getRowHeaderFontStyle(index).intValue(),
            getRowHeaderFontSize(index).intValue());
        if (LabeledTable.this.getRowHeaderTextAttribute(index).equals(TextAttribute.UNDERLINE_ON)) {
          headerFont = headerFont.deriveFont(TableFormattingConstants.underlineMap);
        }
        label.setFont(headerFont);
       
       
        // Set the row header height to match the table row.
        int rowHeight = table.getRowHeight(index);
        Dimension d = label.getMinimumSize();
        d.setSize(d.getWidth() + 2*ROW_HEADER_MARGIN, rowHeight);
        label.setPreferredSize(d);
       
        int r = index - table.getSelectedRow();
       
        if (r >= 0 && r < table.getSelectedRowCount() &&
          table.getSelectedColumnCount() == table.getColumnCount()) {
          label.setBackground(table.getSelectionBackground());
          label.setForeground(table.getSelectionForeground());
        } else {
          label.setBackground(LabeledTable.this.getRowHeaderBackgroundColor(index));
          label.setForeground(table.getTableHeader().getForeground());
        }
        label.setForeground(getRowHeaderFontColor(index));
        label.setBackground(LabeledTable.this.getRowHeaderBackgroundColor(index));
       
        BorderState b = getRowHeaderBorderState(index);
        if (b != null) {
          boolean hasNorth = b.hasNorthBorder();
          boolean hasWest = b.hasWestBorder();
          boolean hasSouth = b.hasSouthBorder();
          boolean hasEast = b.hasEastBorder();
          int w = TableCellFormatter.getBorderWidth();
 
          Border outside = BorderFactory.createMatteBorder(hasNorth ? w : 0, hasWest ? w : 0, hasSouth ? w : 0, hasEast ? w : 0,
              getRowHeaderBorderColor(index));
          Border inside = BorderFactory.createEmptyBorder(hasNorth ? 0 : w, hasWest ? 0 : w, hasSouth ? 0 : w, hasEast ? 0 : w);
          label.setBorder(BorderFactory.createCompoundBorder(outside,inside));
        }
        return label;
      }
     
    });
   
    titleLabelList = new JList(new String[]{" "});
    titleLabelList.setEnabled(false);
   
    setTableFont(titleLabelList);
   
    titleLabelList.setCellRenderer(new ListCellRenderer() {
 
      @Override
      public Component getListCellRendererComponent(JList list,
          Object value, int index, boolean isSelected,
          boolean hasFocus) {
View Full Code Here

    rowForegroundColorComboBox.setToolTipText("Font color");
    rowForegroundColorComboBox.setMaximumRowCount(5);
    rowForegroundColorComboBox.setPreferredSize(new Dimension(50, 20));
    rowForegroundColorComboBox.setSelectedIndex(0);
   
        rowForegroundColorComboBox.setRenderer(new ListCellRenderer() {
         
          private ColorPanel myColorPanel = new ColorPanel(new Color(0));
         
      @Override
      public Component getListCellRendererComponent(JList list,
          Object obj, int arg2, boolean arg3, boolean arg4) { 
       
        if (obj instanceof Color) {
          myColorPanel.setColor((Color) obj);
          return myColorPanel;
        }
        return new JPanel();
      }
     
    });

        // Attach listener to show colors in combo box.
        rowForegroundColorComboBox.addActionListener(new ActionListener() {
         
            @Override
      public void actionPerformed(ActionEvent e) {
              controller.setRowHeaderFontColor(Color.class.cast(rowForegroundColorComboBox.getSelectedItem()));
            }
        });
       
    columnForegroundColorComboBox = new JComboBox(TableFormattingConstants.ForegroundColors);
    columnForegroundColorComboBox.setName("Column_colorComboBox");
    setAccessibleName(columnForegroundColorComboBox,"COL_FONT_COLOR");
    columnForegroundColorComboBox.setToolTipText("Font color");
    columnForegroundColorComboBox.setMaximumRowCount(5);
    columnForegroundColorComboBox.setPreferredSize(new Dimension(50, 20));
    columnForegroundColorComboBox.setSelectedIndex(0);

        columnForegroundColorComboBox.setRenderer(new ListCellRenderer() {
     
      private ColorPanel myColorPanel = new ColorPanel(new Color(0));
     
    @Override
    public Component getListCellRendererComponent(JList list,
        Object obj, int arg2, boolean arg3, boolean arg4) { 
     
      if (obj instanceof Color) {
        myColorPanel.setColor((Color) obj);
        return myColorPanel;
      }
      return new JPanel();
    }
       
    });
       
        // Attach listener to show border styles in combo box.
    columnForegroundColorComboBox.addActionListener(new ActionListener() {
         
            @Override
      public void actionPerformed(ActionEvent e) {
              controller.setColumnHeaderFontColor(Color.class.cast(columnForegroundColorComboBox.getSelectedItem()));
            }
        });
   
    rowBackgroundColorComboBox = new JComboBox(TableFormattingConstants.ForegroundColors);
    rowBackgroundColorComboBox.setName("Row_background_colorComboBox");
    setAccessibleName(rowBackgroundColorComboBox,"ROW_BACKGROUND_COLOR");
    rowBackgroundColorComboBox.setToolTipText("Background color");
    rowBackgroundColorComboBox.setMaximumRowCount(5);
    rowBackgroundColorComboBox.setPreferredSize(new Dimension(50, 20));
    rowBackgroundColorComboBox.setSelectedIndex(0);
   
        rowBackgroundColorComboBox.setRenderer(new ListCellRenderer() {
         
          private ColorPanel myColorPanel = new ColorPanel(new Color(0));
         
      @Override
      public Component getListCellRendererComponent(JList list,
          Object obj, int arg2, boolean arg3, boolean arg4) { 
       
        if (obj instanceof Color) {
          myColorPanel.setColor((Color) obj);
          return myColorPanel;
        }
        return new JPanel();
      }
         
    });

        // Attach listener to show colors in combo box.
        rowBackgroundColorComboBox.addActionListener(new ActionListener() {
         
       
         
            @Override
      public void actionPerformed(ActionEvent e) {
              controller.setRowHeaderBackgroundColor(Color.class.cast(rowBackgroundColorComboBox.getSelectedItem()));
            }
        });
       
    rowHeaderBorderColorComboBox = new JComboBox(TableFormattingConstants.ForegroundColors);
    rowHeaderBorderColorComboBox.setName("Row_header_border_colorComboBox");
    setAccessibleName(rowHeaderBorderColorComboBox,"ROW_HEADER_BORDER_COLOR");
    rowHeaderBorderColorComboBox.setToolTipText("Border color");
    rowHeaderBorderColorComboBox.setMaximumRowCount(5);
    rowHeaderBorderColorComboBox.setPreferredSize(new Dimension(50, 20));
    rowHeaderBorderColorComboBox.setSelectedIndex(0);
   
    rowHeaderBorderColorComboBox.setRenderer(new ListCellRenderer() {
         
          private ColorPanel myColorPanel = new ColorPanel(new Color(0));
         
      @Override
      public Component getListCellRendererComponent(JList list,
          Object obj, int arg2, boolean arg3, boolean arg4) { 
       
        if (obj instanceof Color) {
          myColorPanel.setColor((Color) obj);
          return myColorPanel;
        }
        return new JPanel();
      }
         
    });

        // Attach listener to show colors in combo box.
    rowHeaderBorderColorComboBox.addActionListener(new ActionListener() {
       
            @Override
      public void actionPerformed(ActionEvent e) {
              controller.setRowHeaderBorderColor(Color.class.cast(rowHeaderBorderColorComboBox.getSelectedItem()));
            }
        });
       
    columnBackgroundColorComboBox = new JComboBox(TableFormattingConstants.ForegroundColors);
    columnBackgroundColorComboBox.setName("Column_background_colorComboBox");
    setAccessibleName(columnBackgroundColorComboBox,"COL_BACKGROUND_COLOR");
    columnBackgroundColorComboBox.setToolTipText("Background color");
    columnBackgroundColorComboBox.setMaximumRowCount(5);
    columnBackgroundColorComboBox.setPreferredSize(new Dimension(50, 20));
    columnBackgroundColorComboBox.setSelectedIndex(0);

    columnBackgroundColorComboBox.setRenderer(new ListCellRenderer() {
         
          private ColorPanel myColorPanel = new ColorPanel(new Color(0));
         
      @Override
      public Component getListCellRendererComponent(JList list,
          Object obj, int arg2, boolean arg3, boolean arg4) { 
       
        if (obj instanceof Color) {
          myColorPanel.setColor((Color) obj);
          return myColorPanel;
        }
        return new JPanel();
      }
         
    });
       
        // Attach listener to show border styles in combo box.
    columnBackgroundColorComboBox.addActionListener(new ActionListener() {
         
            @Override
      public void actionPerformed(ActionEvent e) {
              controller.setColumnHeaderBackgroundColor(Color.class.cast(columnBackgroundColorComboBox.getSelectedItem()));
            }
        });
   
    columnHeaderBorderColorComboBox = new JComboBox(TableFormattingConstants.ForegroundColors);
    columnHeaderBorderColorComboBox.setName("Col_header_border_colorComboBox");
    setAccessibleName(columnHeaderBorderColorComboBox,"COL_HEADER_BORDER_COLOR");
    columnHeaderBorderColorComboBox.setToolTipText("Border color");
    columnHeaderBorderColorComboBox.setMaximumRowCount(5);
    columnHeaderBorderColorComboBox.setPreferredSize(new Dimension(50, 20));
    columnHeaderBorderColorComboBox.setSelectedIndex(0);
   
    columnHeaderBorderColorComboBox.setRenderer(new ListCellRenderer() {
         
          private ColorPanel myColorPanel = new ColorPanel(new Color(0));
         
      @Override
      public Component getListCellRendererComponent(JList list,
          Object obj, int arg2, boolean arg3, boolean arg4) { 
       
        if (obj instanceof Color) {
          myColorPanel.setColor((Color) obj);
          return myColorPanel;
        }
        return new JPanel();
      }
         
    });

        // Attach listener to show colors in combo box.
    columnHeaderBorderColorComboBox.addActionListener(new ActionListener() {
       
            @Override
      public void actionPerformed(ActionEvent e) {
              controller.setColumnHeaderBorderColor(Color.class.cast(columnHeaderBorderColorComboBox.getSelectedItem()));
            }
        });
   
    cellFontColorComboBox = new JComboBox(TableFormattingConstants.ForegroundColors);
    setAccessibleName(cellFontColorComboBox,"CELL_FONT_COLOR");
    cellFontColorComboBox.setName("Cell_colorComboBox");
    cellFontColorComboBox.setToolTipText("Font color");
    cellFontColorComboBox.setMaximumRowCount(5);
    cellFontColorComboBox.setPreferredSize(new Dimension(50, 20));
    cellFontColorComboBox.setSelectedIndex(0);

    cellFontColorComboBox.setRenderer(new ListCellRenderer() {
         
          private ColorPanel myColorPanel = new ColorPanel(new Color(0));
         
      @Override
      public Component getListCellRendererComponent(JList list,
          Object obj, int arg2, boolean arg3, boolean arg4) { 
       
        if (obj instanceof Color) {
          myColorPanel.setColor((Color) obj);
          return myColorPanel;
        }
        return new JPanel();
      }
       
    });
       
        // Attach listener to show border styles in combo box.
    cellFontColorComboBox.addActionListener(new ActionListener() {
         
            @Override
      public void actionPerformed(ActionEvent e) {
              controller.setCellFontColor(Color.class.cast(cellFontColorComboBox.getSelectedItem()));
            }
        });
   
    cellBackgroundColorComboBox = new JComboBox(TableFormattingConstants.ForegroundColors);
    setAccessibleName(cellBackgroundColorComboBox,"CELL_BACKGROUND_COLOR");
    cellBackgroundColorComboBox.setName("Cell_BackgroundColorComboBox");
    cellBackgroundColorComboBox.setToolTipText("Background color");
    cellBackgroundColorComboBox.setMaximumRowCount(5);
    cellBackgroundColorComboBox.setPreferredSize(new Dimension(50, 20));
    cellBackgroundColorComboBox.setSelectedIndex(0);

    cellBackgroundColorComboBox.setRenderer(new ListCellRenderer() {
         
          private ColorPanel myColorPanel = new ColorPanel(new Color(0));
         
      @Override
      public Component getListCellRendererComponent(JList list,
View Full Code Here

        JPanel toListPanel = new JPanel(new BorderLayout());
        {
            modulesInMinimalWorkspaceList = new JList();
            modulesInMinimalWorkspaceList.setModel(new DefaultListModel());
           
            modulesInMinimalWorkspaceList.setCellRenderer(new ListCellRenderer() {
                private final JLabel label = new JLabel();
                private final Font origFont = label.getFont();
                private final Font boldFont = origFont.deriveFont(Font.BOLD);
               
                public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
View Full Code Here

        if (hasFocus)
            super.paintComponent(g);
        else {
            list.setEnabled(combo.isEnabled());

            ListCellRenderer renderer = combo.getRenderer();
            Component c = renderer.getListCellRendererComponent(list, combo
                    .getSelectedItem(), -1, false, false);
           
            //fill background first
            Color oldColor = g.getColor();
            g.setColor(getBackground());
View Full Code Here

TOP

Related Classes of javax.swing.ListCellRenderer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.