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

The following examples show how to use javax.swing.JPanel#setForeground() . 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
Source File: TopPanel.java    From ganttproject with GNU General Public License v3.0 6 votes vote down vote up
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 File: JPanelRenderer.java    From Spark with 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 File: HistoryItemRenderer.java    From Spark with 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 File: FastpathPanelRenderer.java    From Spark with 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
Source File: TableCellRenderers.java    From jeveassets with GNU General Public License v2.0 5 votes vote down vote up
@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
Source File: JPanelFactory.java    From WorldGrower with GNU General Public License v3.0 5 votes vote down vote up
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
Source File: JPanelFactory.java    From WorldGrower with GNU General Public License v3.0 5 votes vote down vote up
public static JPanel createBorderlessPanel() {
	JPanel panel = new JPanel();
	panel.setOpaque(false);
	panel.setForeground(ColorPalette.FOREGROUND_COLOR);
	
	return panel;
}
 
Example 8
Source File: PlayersJList.java    From magarena with GNU General Public License v3.0 5 votes vote down vote up
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
Source File: AvatarListCellRenderer.java    From magarena with GNU General Public License v3.0 5 votes vote down vote up
@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 File: CallHistoryRenderer.java    From Spark with 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
Source File: RRDraw.java    From XiaomiRobotVacuumProtocol with GNU General Public License v3.0 4 votes vote down vote up
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
Source File: PeakPreviewComboRenderer.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
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;
}