Java Code Examples for javax.swing.JLabel.setIcon()

The following are Jave code examples for showing how to use setIcon() of the javax.swing.JLabel class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: TableSorter.java   View Source Code Vote up 6 votes
public Component getTableCellRendererComponent(JTable table,
        Object value,
        boolean isSelected,
        boolean hasFocus,
        int row,
        int column) {
    Component c = tableCellRenderer.getTableCellRendererComponent(table,
            value, isSelected, hasFocus, row, column);
    if (c instanceof JLabel) {
        JLabel l = (JLabel) c;
        l.setHorizontalTextPosition(JLabel.LEFT);
        int modelColumn = table.convertColumnIndexToModel(column);
        l.setIcon(getHeaderRendererIcon(modelColumn, l.getFont().getSize()));
    }
    return c;
}
 
Example 2
Project: incubator-netbeans   File: Utils.java   View Source Code Vote up 6 votes
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                                              boolean cellHasFocus) {
    JLabel renderer = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    renderer.setBorder(BorderFactory.createEmptyBorder(1, 7, 1, 5));

    if (value instanceof ProfilingPoint) {
        boolean enabled = ((ProfilingPoint) value).isEnabled();
        renderer.setText(((ProfilingPoint) value).getName());
        renderer.setIcon(enabled ? ((ProfilingPoint) value).getFactory().getIcon() :
                                   ((ProfilingPoint) value).getFactory().getDisabledIcon());
        renderer.setEnabled(enabled);
    } else if (value instanceof ProfilingPointFactory) {
        renderer.setText(((ProfilingPointFactory) value).getType());
        renderer.setIcon(((ProfilingPointFactory) value).getIcon());
        renderer.setEnabled(true);
    } else {
        renderer.setIcon(null);
        renderer.setEnabled(true);
    }

    return renderer;
}
 
Example 3
Project: incubator-netbeans   File: LanguagesNavigator.java   View Source Code Vote up 6 votes
public Component getTreeCellRendererComponent (
    JTree tree, Object value,
    boolean sel,
    boolean expanded,
    boolean leaf, int row,
    boolean hasFocus
) {
    JLabel l = (JLabel) super.getTreeCellRendererComponent (
        tree, value, sel, expanded, leaf, row, hasFocus
    );

    if (value instanceof DefaultMutableTreeNode) {
        l.setIcon (null);
        l.setText ((String) ((DefaultMutableTreeNode) value).getUserObject ());
        return l;
    }
    LanguagesNavigatorModel model = (LanguagesNavigatorModel) tree.getModel ();
    l.setIcon (getCIcon (model.getIcon (value)));
    l.setText (model.getDisplayName (value));
    return l;
}
 
Example 4
Project: VASSAL-src   File: SpecialDiceButton.java   View Source Code Vote up 6 votes
public SpecialDiceButton() {
  dialog = new JDialog(GameModule.getGameModule().getFrame());
  dialog.setLayout(new MigLayout("ins 0"));
  dialogLabel = new JLabel();
  dialogLabel.setIcon(resultsIcon);
  dialog.add(dialogLabel);
  final ActionListener rollAction = new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      DR();
    }
  };
  launch = new LaunchButton(null, TOOLTIP, BUTTON_TEXT, HOTKEY, ICON, rollAction);
  final String desc = Resources.getString("Editor.SpecialDiceButton.symbols"); //$NON-NLS-1$
  setAttribute(NAME, desc);
  setAttribute(BUTTON_TEXT, desc);
  launch.setAttribute(TOOLTIP, desc);
}
 
Example 5
Project: SER316-Aachen   File: App.java   View Source Code Vote up 6 votes
/**
 * Method showSplash.
 */
private void showSplash() {
	splash = new JFrame();
	ImageIcon spl =
		new ImageIcon(App.class.getResource("resources/splash.png"));
	JLabel l = new JLabel();
	l.setSize(400, 300);
	l.setIcon(spl);
	splash.getContentPane().add(l);
	splash.setSize(400, 300);
	Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
	splash.setLocation(
		(screenSize.width - 400) / 2,
		(screenSize.height - 300) / 2);
	splash.setUndecorated(true);
	splash.setVisible(true);
}
 
Example 6
Project: rapidminer   File: EnumComboBoxCellRenderer.java   View Source Code Vote up 5 votes
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
		boolean cellHasFocus) {
	JLabel listCellRendererComponent = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index,
			isSelected, cellHasFocus);

	String text = textCache.get(value);
	ImageIcon icon = iconCache.get(value);
	if (text == null) {

		// get enum text
		text = I18N.getMessageOrNull(I18N.getGUIBundle(), "gui.label." + i18nKeyPrefix + "." + value + ".label");
		if (text != null) {
			textCache.put(value, text);
		} else {
			text = i18nKeyPrefix + "." + value;
		}

		// create label icon
		String iconId = I18N.getMessageOrNull(I18N.getGUIBundle(), "gui.label." + i18nKeyPrefix + "." + value + ".icon");
		if (iconId != null) {
			icon = SwingTools.createIcon("16/" + iconId);
			iconCache.put(value, icon);
		}
	}

	// set text and icon
	listCellRendererComponent.setText(text);
	listCellRendererComponent.setIcon(icon);

	return listCellRendererComponent;
}
 
Example 7
Project: jmt   File: KMeansInfoClustering.java   View Source Code Vote up 5 votes
private JLabel setPie1() {
	int[] angle = new int[numClust];
	double[] prc = info.percent;
	int i;

	angle[0] = 0;
	for (i = 1; i < numClust; i++) {
		angle[i] = angle[i - 1] + (int) ((360) * prc[i - 1]);
	}
	for (; i < angle.length; i++) {
		angle[i] = 360;
	}
	final JLabel l = new JLabel();
	final pieChartIcon p = new pieChartIcon(numClust);
	l.addMouseMotionListener(new MouseMotionAdapter() {
		@Override
		public void mouseMoved(MouseEvent e) {
			int pos;

			pos = p.getPosXY(e.getX(), e.getY());

			if (pos != -1) {
				l.setToolTipText(tableClusters.getValueAt(pos, 2).toString());
			} else {
				l.setToolTipText("");
			}
		}
	});
	p.setAngle(angle);
	l.setIcon(p);
	return l;
}
 
Example 8
Project: jmt   File: JWatMainPanel.java   View Source Code Vote up 5 votes
public JWatMainPanel(MainJwatWizard parent) {
	this.parent = parent;
	this.help = parent.getHelp();
	this.setLayout(new BorderLayout());
	JPanel upper = new JPanel(new FlowLayout());
	JLabel upperLabel = new JLabel();
	upperLabel.setPreferredSize(new Dimension(300, 10));
	upper.add(upperLabel);

	JPanel bottom = new JPanel(new FlowLayout());
	JLabel bottomLabel = new JLabel();
	bottomLabel.setPreferredSize(new Dimension(300, 10));
	bottom.add(bottomLabel);

	this.add(upper, BorderLayout.NORTH);
	this.add(bottom, BorderLayout.SOUTH);

	JPanel eastPanel = new JPanel(new FlowLayout());
	eastPanel.add(Box.createVerticalStrut(5), BorderLayout.NORTH);
	JPanel buttonPanel = new JPanel(new GridLayout(buttonAction.length, 1, 2, 15));
	eastPanel.add(buttonPanel, BorderLayout.CENTER);
	for (AbstractAction element : buttonAction) {
		buttonPanel.add(createButton(element));
	}
	JLabel imageLabel = new JLabel();
	imageLabel.setBorder(BorderFactory.createEmptyBorder(BUTTONSIZE - 5, 1, 0, 0));
	//imageLabel.setIcon(new ImageIcon(image));
	imageLabel.setIcon(new ImageIcon(new ImageIcon(imageURL).getImage().getScaledInstance(400, 315, Image.SCALE_SMOOTH)));
	imageLabel.setHorizontalAlignment(SwingConstants.RIGHT);
	imageLabel.setVerticalAlignment(SwingConstants.NORTH);

	//JLabel description = new JLabel("<html><body><h3>This is a simple<br>descirption added to this<br>page. Please do not mind it<br>will be replaced soon</h3></body></html>");
	//this.add(description,BorderLayout.WEST);
	this.add(imageLabel, BorderLayout.CENTER);
	this.add(eastPanel, BorderLayout.EAST);
	makeToolbar();
	makeMenubar();
}
 
Example 9
Project: dztools   File: PinProvider.java   View Source Code Vote up 5 votes
public PinDialog() throws Exception {
    super(noParentFrame, "PIN Dialog", true);

    final JPanel captchaPanel = new JPanel();
    captchaPanel.setLayout(new BoxLayout(captchaPanel, BoxLayout.Y_AXIS));

    final JLabel captchaImage = new JLabel();
    captchaImage.setIcon(new ImageIcon(client.getCaptchaImage(liveURL)));
    captchaPanel.add(captchaImage);

    captchaPanel.add(pinfield);
    getContentPane().add(captchaPanel);

    final JPanel buttonPane = new JPanel();

    final JButton btnLogin = new JButton("Login");
    buttonPane.add(btnLogin);
    btnLogin.addActionListener(e -> {
        setVisible(false);
        dispose();
    });

    final JButton btnReload = new JButton("Reload");
    buttonPane.add(btnReload);
    btnReload.addActionListener(e -> {
        try {
            captchaImage.setIcon(new ImageIcon(client.getCaptchaImage(liveURL)));
        } catch (final Exception ex) {
            logger.error("Get captcha image for pin faile! " + ex.getMessage());
            Zorro.indicateError();
        }
    });
    getContentPane().add(buttonPane, BorderLayout.SOUTH);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    pack();
    setVisible(true);
}
 
Example 10
Project: litiengine   File: PropPanel.java   View Source Code Vote up 5 votes
private void loadAvailableProps() {
  Map<String, String> m = new TreeMap<>();
  for (Spritesheet s : Spritesheet.getSpritesheets()) {
    String spriteName = s.getName();
    if (spriteName.startsWith("prop-")) {
      String[] parts = spriteName.split("-");
      String propName = parts[1];
      if (!m.containsKey(propName)) {
        m.put(propName, spriteName);
      }
    }
  }

  this.comboBoxSpriteSheets.removeAllItems();
  for (String key : m.keySet()) {
    JLabel label = new JLabel();
    label.setText(key);
    String value = m.get(key);
    Spritesheet sprite = Spritesheet.find(value);
    if (sprite != null && sprite.getTotalNumberOfSprites() > 0) {
      BufferedImage img = sprite.getSprite(0);
      BufferedImage scaled = ImageProcessing.scaleImage(img, 24, 24, true);
      if (scaled != null) {
        label.setIcon(new ImageIcon(scaled));
      }
    }

    this.comboBoxSpriteSheets.addItem(label);
  }

}
 
Example 11
Project: VISNode   File: AboutVISNodePanel.java   View Source Code Vote up 5 votes
/**
 * Builds the tool icon
 *
 * @return JComponent
 */
private JComponent buildIcon() {
    JLabel icon = new JLabel();
    try {
        icon.setIcon(new ImageIcon(ImageIO.read(getClass().getResourceAsStream("/VISNode_64.png"))));
        icon.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 15));
    } catch (IOException ex) {
        Logger.getLogger(AboutVISNodePanel.class.getName()).log(Level.SEVERE, null, ex);
    }
    return icon;
}
 
Example 12
Project: QN-ACTR-Release   File: KMeansInfoClustering.java   View Source Code Vote up 5 votes
private JLabel setPie2(int var) {
	int[] angle = new int[numClust];
	int i;

	angle[0] = 0;
	for (i = 1; i < numClust; i++) {
		angle[i] = angle[i - 1] + (int) ((360) * info.infoCluster[i].percVar[var]);
	}
	for (; i < angle.length; i++) {
		angle[i] = 360;
	}

	final JLabel l = new JLabel();
	pieChartVars = new pieChartIcon(numClust);
	l.addMouseMotionListener(new MouseMotionAdapter() {
		@Override
		public void mouseMoved(MouseEvent e) {
			int pos;

			pos = pieChartVars.getPosXY(e.getX(), e.getY());

			if (pos != -1) {
				l.setToolTipText(tableVars.getValueAt(pos, 1).toString());
			} else {
				l.setToolTipText("");
			}
		}
	});
	pieChartVars.setAngle(angle);
	l.setIcon(pieChartVars);
	return l;
}
 
Example 13
Project: rapidminer   File: QuickFixDialog.java   View Source Code Vote up 5 votes
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
		boolean cellHasFocus) {
	JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
	if (value instanceof QuickFix) {
		label.setIcon((Icon) ((QuickFix) value).getAction().getValue(Action.SMALL_ICON));
	}
	return label;
}
 
Example 14
Project: jmt   File: KMeansInfoClustering.java   View Source Code Vote up 5 votes
private JLabel setPie2(int var) {
	int[] angle = new int[numClust];
	int i;

	angle[0] = 0;
	for (i = 1; i < numClust; i++) {
		angle[i] = angle[i - 1] + (int) ((360) * info.infoCluster[i].percVar[var]);
	}
	for (; i < angle.length; i++) {
		angle[i] = 360;
	}

	final JLabel l = new JLabel();
	pieChartVars = new pieChartIcon(numClust);
	l.addMouseMotionListener(new MouseMotionAdapter() {
		@Override
		public void mouseMoved(MouseEvent e) {
			int pos;

			pos = pieChartVars.getPosXY(e.getX(), e.getY());

			if (pos != -1) {
				l.setToolTipText(tableVars.getValueAt(pos, 1).toString());
			} else {
				l.setToolTipText("");
			}
		}
	});
	pieChartVars.setAngle(angle);
	l.setIcon(pieChartVars);
	return l;
}
 
Example 15
Project: Equella   File: WorkflowCellRenderer.java   View Source Code Vote up 5 votes
@SuppressWarnings({"unchecked", "cast"})
private void setup(JLabel label, Object value)
{
	Class<? extends WorkflowNode> klass = null;
	LanguageBundle name = null;

	if( value instanceof Class )
	{
		klass = (Class<? extends WorkflowNode>) value;
	}
	else
	{
		WorkflowNode node = (WorkflowNode) value;
		klass = node.getClass();
		name = node.getName();
	}

	Pair<String, Icon> defaults = nameAndIcon.get(klass);

	if( name != null )
	{
		label.setText(CurrentLocale.get(name, defaultString));
	}
	else
	{
		label.setText(defaults.getFirst());
	}

	label.setIcon(defaults.getSecond());
}
 
Example 16
Project: Progetto-B   File: CardListener.java   View Source Code Vote up 5 votes
/**
 * When the cursor exits a card, the card is moved back to its original
 * depth.
 *
 * @param e
 */
@Override
public void mouseExited(MouseEvent e) {
    if (game.getPhase().equals(PLAY_CARDS)) {
        JLabel label = (JLabel) e.getComponent();
        cardPanel.getCardsPane().setLayer(label, cardPanel.getLabelLayer(label));
        String card = (String) label.getClientProperty("name");
        label.setIcon(new ImageIcon("src/resources/images/" + card + ".png"));
        Point p = label.getLocation();
        Point p1 = new Point(p.x, LOW_Y);
        label.setLocation(p1);
        cardPanel.updateUI();
    }
}
 
Example 17
Project: Reinickendorf_SER316   File: JNCalendarCellRenderer.java   View Source Code Vote up 4 votes
public Component getTableCellRendererComponent(
      JTable table,
      Object value,
      boolean isSelected,
      boolean hasFocus,
      int row,
      int column) {
      
JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
String currentPanel = ((AppFrame)App.getFrame()).workPanel.dailyItemsPanel.getCurrentPanel();

if (d == null) {
          label.setEnabled(false);
	label.setIcon(null);
	PreferencesDialog.setJComponentBGandFG(label);
          return label;
      }
      
if (!isSelected) {
	CalendarDate cpsd = CurrentProject.get().getStartDate();
          CalendarDate cped = CurrentProject.get().getEndDate();
          if (!(((d.after(cpsd)) && (d.before(cped))) || (d.equals(cpsd)) || (d.equals(cped)))) {
		PreferencesDialog.setJComponentBGandFG(label);
		return label;
	}
      }		


label.setHorizontalTextPosition(2);
label.setEnabled(true);



      if (d.equals(CalendarDate.today())) {
          label.setBorder(BorderFactory.createLineBorder(new Color(100, 100, 128)));
      }
      
// set foreground color
if (d.getCalendar().get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
          label.setForeground(new Color(255, 0, 0));
      }
else { 		
	label.setForeground(Color.BLACK);
}

// set background color
if (currentPanel == null)
	PreferencesDialog.setJComponentBGandFG(label);
else if (currentPanel.equals("TASKS") && (t != null) && 
	(d.inPeriod(t.getStartDate(), t.getEndDate()))) 
		label.setBackground( new Color(230, 255, 230));

else if(currentPanel.equals("NOTES") && 
CurrentProject.getNoteList().getNoteForDate(d) != null) 
			label.setBackground(new Color(255,245,200));

else if(currentPanel.equals("EVENTS") && 
(!(EventsManager.getEventsForDate(d).isEmpty()))) 
			label.setBackground(new Color(255,230,230));

else if(!isSelected)
	PreferencesDialog.setJComponentBGandFG(label);
		
// always display NREvents
if (EventsManager.isNREventsForDate(d))
	label.setIcon(evIcon);
else
	label.setIcon(null);

      return label;
  }
 
Example 18
Project: VASSAL-src   File: HtmlChart.java   View Source Code Vote up 4 votes
protected Component createComponent() {
  final JLabel label = new JLabel();
  label.setIcon(new OpIcon(srcOp));
  return label;
}
 
Example 19
Project: incubator-netbeans   File: SearchField.java   View Source Code Vote up 4 votes
private void initComponents() {
    java.awt.GridBagConstraints gridBagConstraints;

    panel = new JPanel();
    leftIcon = new JLabel();
    txtSearch = new SearchTextField();
    txtSearch.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            if (e.getSource() == txtSearch) {
                // make sure nothing is selected
                int n = txtSearch.getText().length();
                txtSearch.select(n, n);
            }
        }
    });
    separator = new javax.swing.JSeparator();

    setLayout(new java.awt.GridBagLayout());

    panel.setBackground(Utils.getTextBackground());
    panel.setBorder(javax.swing.BorderFactory.createLineBorder(Utils.getComboBorderColor()));
    panel.setLayout(new java.awt.GridBagLayout());

    leftIcon.setIcon(ImageUtilities.loadImageIcon("org/netbeans/modules/notifications/resources/find.png", true));//NOI18N
    leftIcon.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.weighty = 1.0;
    gridBagConstraints.insets = new java.awt.Insets(1, 2, 1, 1);
    panel.add(leftIcon, gridBagConstraints);

    txtSearch.setBorder(null);
    txtSearch.setMinimumSize(new java.awt.Dimension(100, 18));
    txtSearch.setPreferredSize(new java.awt.Dimension(150, 18));

    separator.setOrientation(javax.swing.SwingConstants.VERTICAL);
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
    gridBagConstraints.weighty = 1.0;
    gridBagConstraints.insets = new java.awt.Insets(3, 0, 3, 3);
    panel.add(separator, gridBagConstraints);

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 2;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.CENTER;
    gridBagConstraints.weighty = 1.0;
    gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 2);
    panel.add(txtSearch, gridBagConstraints);

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints.weightx = 1.0;
    add(panel, gridBagConstraints);
}
 
Example 20
Project: incubator-netbeans   File: RepositoryFormPanel.java   View Source Code Vote up 4 votes
private void initComponents() {
    cardsPanel = new JPanel(new CardLayout());

    errorLabel = new JLabel();
    errorLabel.setForeground(ERROR_COLOR);
    errorLabel.setIcon(new ImageIcon(ImageUtilities.loadImage(
            "org/netbeans/modules/bugtracking/ui/resources/error.gif")));   //NOI18N
    errorText = new JTextArea();
    errorText.setForeground(ERROR_COLOR);
    errorText.setBackground(errorLabel.getBackground());
    errorText.setEditable(false);
    
    errorScrollPane = new javax.swing.JScrollPane();
    errorScrollPane.setBorder(null);
    errorScrollPane.setViewportView(errorText);
    
    updateErrorMessage(" ");                                        //NOI18N
    
    GroupLayout layout = new GroupLayout(this);
    setLayout(layout);
    
    int height = errorText.getFont().getSize() * 3;
    
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(cardsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(errorLabel)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(errorScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE)))
            .addContainerGap())
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(cardsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGap(6, 14, 14)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(errorScrollPane, height, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(errorLabel))
            )
    );
    layout.setHonorsVisibility(false);  //keep space for errorLabel
}