Java Code Examples for javax.swing.JPanel#setForeground()

The following examples show how to use javax.swing.JPanel#setForeground() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public static JComponent create(String title, String comment) {

    JPanel topPanel = new JPanel(new BorderLayout());
    topPanel.setBackground(Color.ORANGE);
    topPanel.setForeground(Color.BLACK);
    topPanel.setBorder(BorderFactory.createLineBorder(Color.ORANGE.darker()));

    String labelText = "<html>";
    if (title != null) {
        labelText += "<b>" + title + "</b>";
    }
    if (comment != null) {
      labelText += "<br>" + comment;
    }
    labelText += "</html>";

    JLabel labelTitle = new JLabel(labelText);
    labelTitle.setBorder(BorderFactory.createEmptyBorder(2, 5, 2, 5));
    topPanel.add(labelTitle, BorderLayout.NORTH);
    return topPanel;
  }
 
Example 2
Source Project: Spark   File: JPanelRenderer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList list,
                                                 Object value,
                                                 int index,
                                                 boolean isSelected,
                                                 boolean cellHasFocus) {
       JPanel panel = (JPanel)value;
       panel.setFocusable(false);

       if (isSelected) {
           panel.setForeground((Color)UIManager.get("List.selectionForeground"));
           panel.setBackground((Color)UIManager.get("List.selectionBackground"));
           panel.setBorder(BorderFactory.createLineBorder((Color)UIManager.get("List.selectionBorder")));
       }
       else {
           panel.setBackground(list.getBackground());
           panel.setForeground(list.getForeground());
           panel.setBorder(BorderFactory.createLineBorder((Color)UIManager.get("ContactItem.background")));
       }

       list.setBackground((Color)UIManager.get("ContactItem.background"));


       return panel;
   }
 
Example 3
Source Project: Spark   File: HistoryItemRenderer.java    License: Apache License 2.0 6 votes vote down vote up
public Component getListCellRendererComponent(JList list,
                                              Object value,
                                              int index,
                                              boolean isSelected,
                                              boolean cellHasFocus) {
    JPanel panel = (JPanel)value;
    panel.setFocusable(false);

    if (isSelected) {
        panel.setForeground(Color.black);
        panel.setBackground(new Color(217, 232, 250));
        panel.setBorder(BorderFactory.createLineBorder(new Color(187, 195, 215)));
    }
    else {
        panel.setBackground(list.getBackground());
        panel.setForeground(list.getForeground());
        panel.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.LIGHT_GRAY));

    }

    return panel;
}
 
Example 4
Source Project: Spark   File: FastpathPanelRenderer.java    License: Apache License 2.0 6 votes vote down vote up
public Component getListCellRendererComponent(JList list,
                                              Object value,
                                              int index,
                                              boolean isSelected,
                                              boolean cellHasFocus) {
    JPanel panel = (JPanel)value;
    panel.setFocusable(false);

    if (isSelected) {
        panel.setForeground((Color)UIManager.get("List.selectionForeground"));
        panel.setBackground((Color)UIManager.get("List.selectionBackground"));
        panel.setBorder(BorderFactory.createLineBorder((Color)UIManager.get("List.selectionBorder")));
    }
    else {
        panel.setBackground(list.getBackground());
        panel.setForeground(list.getForeground());
        panel.setBorder(BorderFactory.createMatteBorder(0,0,1,0, Color.lightGray));
    }

    list.setBackground((Color)UIManager.get("List.background"));


    return panel;
}
 
Example 5
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
	JLabel jLabel = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); //To change body of generated methods, choose Tools | Templates.
	if (value instanceof Tags) {
		Tags tags = (Tags) value;
		JPanel jPanel = tags.getPanel();
		jPanel.setBackground(jLabel.getBackground());
		jPanel.setForeground(jLabel.getForeground());
		jPanel.setBorder(jLabel.getBorder());
		return jPanel;
	}
	return jLabel;
}
 
Example 6
public static JPanel createJPanel(String title) {
	JPanel panel = new JPanel();
	panel.setBorder(createBorder(title));
	panel.setOpaque(false);
	panel.setForeground(ColorPalette.FOREGROUND_COLOR);
	
	return panel;
}
 
Example 7
public static JPanel createBorderlessPanel() {
	JPanel panel = new JPanel();
	panel.setOpaque(false);
	panel.setForeground(ColorPalette.FOREGROUND_COLOR);
	
	return panel;
}
 
Example 8
private JPanel getNamePanel() {
    final JPanel panel = new JPanel(new MigLayout("insets 0, gap 0, flowy"));
    panel.setOpaque(false);
    panel.setForeground(foreColor);
    panel.add(getPlayerNameLabel());
    panel.add(getPlayerSettingsLabel());
    return panel;
}
 
Example 9
@Override
public Component getListCellRendererComponent(
        JList<? extends AvatarImageSet> list,
        AvatarImageSet value,
        int index,
        boolean isSelected,
        boolean cellHasFocus) {

    final Color foreColor = isSelected ? MagicStyle.getRolloverColor() : Color.WHITE;

    final JLabel setNameLabel = new JLabel(value.getName());
    setNameLabel.setFont(FontsAndBorders.FONT2);
    setNameLabel.setForeground(foreColor);
    setNameLabel.setVerticalAlignment(SwingConstants.TOP);

    final JPanel infoPanel = new JPanel(new MigLayout("insets 0, gap 0, flowy"));
    infoPanel.setOpaque(false);
    infoPanel.setForeground(foreColor);
    infoPanel.add(setNameLabel, "w 100%, gapbottom 4");

    final JPanel itemPanel = new JPanel(new MigLayout("insets 0 0 0 6, gap 0"));
    itemPanel.setPreferredSize(new Dimension(0, 70));
    itemPanel.setOpaque(false);
    itemPanel.setForeground(foreColor);
    itemPanel.setBorder(isSelected ? BorderFactory.createLineBorder(MagicStyle.getRolloverColor(), 1) : null);
    itemPanel.add(new JLabel(value.getSampleImage()), "w 70!, h 70!");
    itemPanel.add(infoPanel, "w 100%");
    return itemPanel;

}
 
Example 10
Source Project: Spark   File: CallHistoryRenderer.java    License: Apache License 2.0 5 votes vote down vote up
public Component getListCellRendererComponent(JList list,
                                              Object value,
                                              int index,
                                              boolean isSelected,
                                              boolean cellHasFocus) {
    JPanel panel = (JPanel)value;
    panel.setFocusable(false);

    if (isSelected) {
        panel.setForeground(Color.white);
        panel.setBackground(new Color(51, 136, 238));
        panel.setBorder(BorderFactory.createLineBorder((Color)UIManager.get("List.selectionBorder")));
    }
    else {
        if (index % 2 == 0) {
            panel.setBackground((Color)UIManager.get("List.selectionBackground"));
        }
        else {
            panel.setBackground(list.getBackground());
        }
        panel.setForeground(list.getForeground());
        panel.setBorder(BorderFactory.createLineBorder((Color)UIManager.get("List.background")));
    }

    list.setBackground((Color)UIManager.get("List.background"));


    return panel;
}
 
Example 11
public RRDraw() {
    super("RR Map Viewer");
    setSize(350, 400);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    parent = this;
    rrDrawPanel = new RRDrawPanel();
    Container c = getContentPane();
    // The default BorderLayout will work better.
    // c.setLayout(new FlowLayout());

    JButton openButton = new JButton("Open");
    final JLabel statusbar = new JLabel("Output of your selection will go here");

  //  File file = new File("C:\\temp\\map\\roboroommap7.gz");
  //  RRFileParser loadImage = loadImage(file);
  //  statusbar.setText(file.getName() + " size " + loadImage.getImgWidth() + "x" + loadImage.getImgHeight());
  //  rrDrawPanel.setSize(loadImage.getImgWidth(), loadImage.getImgHeight());

    openButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            JFileChooser chooser = new JFileChooser("images");

            int option = chooser.showOpenDialog(parent);
            if (option == JFileChooser.APPROVE_OPTION) {
                File file = chooser.getSelectedFile();
                RRFileParser loadImage = loadImage(file);
                statusbar.setText(file.getName() + " size " + loadImage.getImgWidth() + "x" + loadImage.getImgHeight());
                rrDrawPanel.setSize(loadImage.getImgWidth(), loadImage.getImgHeight());
        
            } else {
                statusbar.setText("You cancelled.");
            }
        }
    });

    JPanel north = new JPanel();
    north.add(openButton);
    north.add(statusbar);

    north.setBackground(Color.GRAY);
    north.setForeground(Color.BLUE);
    c.add(north, "First");

    c.add(new JScrollPane(rrDrawPanel), "Center");

}
 
Example 12
public Component getListCellRendererComponent(JList<? extends PeakListRow> combo,
    PeakListRow value, int index, boolean isSelected, boolean cellHasFocus) {

  PeakListRow row = (PeakListRow) value;
  if (row == null)
    return new JPanel();
  Feature peak = row.getPeaks()[0];

  String labelText = "#" + row.getID() + " "
      + MZmineCore.getConfiguration().getMZFormat().format(row.getAverageMZ()) + " m/z ";
  JLabel textComponent = new JLabel(labelText);
  textComponent.setFont(combo.getFont());

  PeakXICComponent shapeComponent = new PeakXICComponent(peak);
  shapeComponent.setBorder(null);

  JPanel panel = new JPanel(new BorderLayout());

  panel.setOpaque(true);
  if (isSelected) {
    panel.setBackground(combo.getSelectionBackground());
    panel.setForeground(combo.getSelectionForeground());
  } else {
    panel.setBackground(combo.getBackground());
    panel.setForeground(combo.getForeground());
  }

  panel.setEnabled(combo.isEnabled());

  Border border = null;
  if (cellHasFocus) {
    if (isSelected) {
      border = UIManager.getBorder("List.focusSelectedCellHighlightBorder");
    }
    if (border == null) {
      border = UIManager.getBorder("List.focusCellHighlightBorder");
    }
  } else {
    border = noFocusBorder;
  }
  panel.setBorder(border);

  panel.add(textComponent, BorderLayout.WEST);
  panel.add(shapeComponent, BorderLayout.CENTER);

  return panel;
}