List of usage examples for javax.swing JLabel setIcon
@BeanProperty(preferred = true, visualUpdate = true, description = "The icon this component will display.") public void setIcon(Icon icon)
From source file:uk.nhs.cfh.dsp.srth.desktop.uiframework.app.impl.ModularApplicationAboutDialog.java
/** * Inits the components.//from w w w.jav a 2 s . com */ public void initComponents() { // initialise gui mainPanel = new JPanel(); JLabel logoLabel = new JLabel(); logoLabel.setIcon(ImageUtils.getIcon(ImageUtils.IconName.LOGO_WHITE)); logoLabel.setBackground(Color.WHITE); logoLabel.setOpaque(true); infoPane = new JTextPane(); infoPane.setEditorKit(new HTMLEditorKit()); infoPane.setText(createHTMLText()); infoPane.setEditable(false); mainPanel.setLayout(new BorderLayout()); mainPanel.add(logoLabel, BorderLayout.NORTH); mainPanel.add(new JScrollPane(infoPane), BorderLayout.CENTER); createButtonsPanel(); getContentPane().add(mainPanel); setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); setPreferredSize(new Dimension(400, 500)); setResizable(true); }
From source file:uk.nhs.cfh.dsp.yasb.searchpanel.renderer.SearchResultListCellRenderer.java
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean hasFocus) { JLabel label = new JLabel(); label.setOpaque(true);//from www . j av a 2 s. co m if (value instanceof Document) { // get field that has value of the fully specified name Document doc = (Document) value; if (isRenderConceptId()) { label.setText("<html><b>" + doc.get("TERM") + "</b><font color=\"eee\">|" + doc.get("CONCEPTID") + "|</font></html>"); } else { label.setText("<html><b>" + doc.get("TERM") + "</b></html>"); } // set icon based on status String status = doc.get("STATUS"); if ("limited".equalsIgnoreCase(status)) { label.setIcon(limitedStatusIcon); } else if ("duplicate".equalsIgnoreCase(status)) { label.setIcon(duplicateStatusIcon); } else if ("ambiguous".equalsIgnoreCase(status)) { label.setIcon(ambiguousStatusIcon); } else { label.setIcon(currentStatusIcon); } // always set tooltip to FSN + concept id label.setToolTipText("<html><b>" + doc.get("TERM") + "</b><font color=\"eee\">|" + doc.get("CONCEPTID") + "|</font></html>"); } if (isSelected) { label.setBackground(UIManager.getColor("Tree.selectionbackground")); } else { label.setBackground(UIManager.getColor("Tree.background")); } return label; }
From source file:utybo.branchingstorytree.swing.editor.StoryNodesEditor.java
public StoryNodesEditor() { setLayout(new MigLayout("", "[:33%:300px][grow 150]", "[grow][]")); JScrollPane scrollPane = new JScrollPane(); scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); add(scrollPane, "cell 0 0,grow"); jlist = new JList<>(); jlist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jlist.setCellRenderer(new SubstanceDefaultListCellRenderer() { @Override/*from ww w .jav a 2 s .com*/ public Component getListCellRendererComponent(@SuppressWarnings("rawtypes") JList list, Object o, int index, boolean isSelected, boolean cellHasFocus) { JLabel label = (JLabel) super.getListCellRendererComponent(list, o, index, isSelected, cellHasFocus); if (o instanceof StorySingleNodeEditor) { if (((StorySingleNodeEditor) o).getStatus() == Status.ERROR) label.setForeground(Color.RED.darker()); if (o instanceof StoryLogicalNodeEditor) label.setIcon(new ImageIcon(Icons.getImage("LogicalNode", 16))); else if (o instanceof StoryTextNodeEditor) label.setIcon(new ImageIcon(Icons.getImage("TextNode", 16))); else if (o instanceof StoryVirtualNodeEditor) label.setIcon(new ImageIcon(Icons.getImage("VirtualNode", 16))); } return label; } }); jlist.addListSelectionListener(e -> { if (jlist.getSelectedValue() instanceof JComponent) { container.removeAll(); container.add(jlist.getSelectedValue()); container.revalidate(); container.repaint(); } }); JScrollablePanel pan = new JScrollablePanel(new BorderLayout(0, 0)); jlist.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { scrollPane.revalidate(); pan.revalidate(); jlist.revalidate(); revalidate(); repaint(); } }); pan.setScrollableWidth(ScrollableSizeHint.FIT); pan.setScrollableHeight(ScrollableSizeHint.STRETCH); pan.add(jlist, BorderLayout.CENTER); scrollPane.setViewportView(pan); container = new JPanel(); add(container, "cell 1 0,grow"); container.setLayout(new BorderLayout(0, 0)); container.add(new JPanel(), BorderLayout.CENTER); // TODO JPanel panel = new JPanel(); add(panel, "cell 0 1 2 1,alignx leading,growy"); JButton btnAddNode = new JButton(Lang.get("editor.panel.add"), new ImageIcon(Icons.getImage("Add Subnode", 16))); btnAddNode.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { createMenu().show(btnAddNode, e.getX(), e.getY()); } }); panel.add(btnAddNode); JButton btnRemoveNode = new JButton(Lang.get("editor.panel.remove"), new ImageIcon(Icons.getImage("Delete Subnode", 16))); btnRemoveNode.addActionListener(e -> removeNode()); panel.add(btnRemoveNode); }
From source file:utybo.branchingstorytree.swing.OpenBSTGUI.java
public OpenBSTGUI() { instance = this; UIManager.put("OptionPane.errorIcon", new ImageIcon(Icons.getImage("Cancel", 48))); UIManager.put("OptionPane.informationIcon", new ImageIcon(Icons.getImage("About", 48))); UIManager.put("OptionPane.questionIcon", new ImageIcon(Icons.getImage("Rename", 48))); UIManager.put("OptionPane.warningIcon", new ImageIcon(Icons.getImage("Error", 48))); BorderLayout borderLayout = new BorderLayout(); borderLayout.setVgap(4);/* w ww . jav a 2 s .co m*/ getContentPane().setLayout(borderLayout); setIconImage(Icons.getImage("Logo", 48)); setTitle("OpenBST " + OpenBST.VERSION); setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { boolean cancelled = false; int i = 0; for (Component c : container.getComponents()) { if (c instanceof StoryPanel) { i++; } else if (c instanceof StoryEditor) { container.setSelectedComponent(c); if (((StoryEditor) c).askClose()) { continue; } else { cancelled = true; break; } } } if (!cancelled) { if (i > 0) { int j = Messagers.showConfirm(OpenBSTGUI.this, "You are about to close " + i + " file(s). Are you sure you wish to exit OpenBST?", Messagers.OPTIONS_YES_NO, Messagers.TYPE_WARNING, "Closing OpenBST"); if (j != Messagers.OPTION_YES) cancelled = true; } if (!cancelled) System.exit(0); } } }); JMenuBar jmb = new JMenuBar(); jmb.setBackground(OPENBST_BLUE); jmb.add(Box.createHorizontalGlue()); jmb.add(createShortMenu()); jmb.add(Box.createHorizontalGlue()); this.setJMenuBar(jmb); addDarkModeCallback(b -> { jmb.setBackground(b ? OPENBST_BLUE.darker().darker() : OPENBST_BLUE); }); container = new JTabbedPane(); container.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); container.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(final MouseEvent e) { if (SwingUtilities.isMiddleMouseButton(e)) { final int i = container.indexAtLocation(e.getX(), e.getY()); System.out.println(i); if (i > -1) { Component c = container.getComponentAt(i); if (c instanceof StoryPanel) { container.setSelectedComponent(c); ((StoryPanel) c).askClose(); } else if (c instanceof StoryEditor) { container.setSelectedComponent(c); ((StoryEditor) c).askClose(); } } } } }); getContentPane().add(container, BorderLayout.CENTER); final JBackgroundPanel welcomeContentPanel = new JBackgroundPanel(Icons.getRandomBackground(), Image.SCALE_FAST); background = welcomeContentPanel; welcomeContentPanel.setLayout(new MigLayout("hidemode 2", "[grow,center]", "[][grow][]")); container.add(welcomeContentPanel); container.setTitleAt(0, Lang.get("welcome")); bannersPanel = new JPanel(new MigLayout("hidemode 2, gap 0px, fill, wrap 1, ins 0")); bannersPanel.setBackground(new Color(0, 0, 0, 0)); welcomeContentPanel.add(bannersPanel, "cell 0 0,grow"); if (OpenBST.VERSION.endsWith("u")) { JButton btnReportBugs = new JButton(Lang.get("welcome.reportbugs")); btnReportBugs.addActionListener(e -> { VisualsUtils.browse("https://github.com/utybo/BST/issues"); }); bannersPanel.add(new JBannerPanel(new ImageIcon(Icons.getImage("Experiment", 32)), Color.YELLOW, Lang.get("welcome.ontheedge"), btnReportBugs, false), "grow"); } else if (OpenBST.VERSION.contains("SNAPSHOT")) { bannersPanel.add(new JBannerPanel(new ImageIcon(Icons.getImage("Experiment", 32)), Color.ORANGE, Lang.get("welcome.snapshot"), null, false), "grow"); } if (System.getProperty("java.specification.version").equals("9")) { bannersPanel.add(new JBannerPanel(new ImageIcon(Icons.getImage("Attention", 32)), new Color(255, 50, 50), Lang.get("welcome.java9warning"), null, false), "grow"); } if (System.getProperty("java.specification.version").equals("10")) { bannersPanel.add(new JBannerPanel(new ImageIcon(Icons.getImage("Attention", 32)), new Color(255, 50, 50), Lang.get("welcome.java10warning"), null, false), "grow"); } JButton btnJoinDiscord = new JButton(Lang.get("openbst.discordjoin")); btnJoinDiscord.addActionListener(e -> { VisualsUtils.browse("https://discord.gg/6SVDCMM"); }); bannersPanel.add(new JBannerPanel(new ImageIcon(Icons.getImage("Discord", 48)), DISCORD_COLOR, Lang.get("openbst.discord"), btnJoinDiscord, true), "grow"); JPanel panel = new JPanel(); panel.setBackground(new Color(0, 0, 0, 0)); welcomeContentPanel.add(panel, "flowx,cell 0 1,growx,aligny center"); panel.setLayout(new MigLayout("", "[40%][][][][60%,growprio 50]", "[][grow]")); final JLabel lblOpenbst = new JLabel(new ImageIcon(Icons.getImage("FullLogo", 48))); addDarkModeCallback(b -> lblOpenbst .setIcon(new ImageIcon(b ? Icons.getImage("FullLogoWhite", 48) : Icons.getImage("FullLogo", 48)))); panel.add(lblOpenbst, "flowx,cell 0 0 1 2,alignx trailing,aligny center"); JSeparator separator = new JSeparator(); separator.setOrientation(SwingConstants.VERTICAL); panel.add(separator, "cell 2 0 1 2,growy"); final JLabel lblWelcomeToOpenbst = new JLabel("<html>" + Lang.get("welcome.intro")); lblWelcomeToOpenbst.setMaximumSize(new Dimension(350, 999999)); panel.add(lblWelcomeToOpenbst, "cell 4 0"); Component horizontalStrut = Box.createHorizontalStrut(10); panel.add(horizontalStrut, "cell 1 1"); Component horizontalStrut_1 = Box.createHorizontalStrut(10); panel.add(horizontalStrut_1, "cell 3 1"); final JButton btnOpenAFile = new JButton(Lang.get("welcome.open")); panel.add(btnOpenAFile, "flowx,cell 4 1"); btnOpenAFile.setIcon(new ImageIcon(Icons.getImage("Open", 40))); btnOpenAFile.addActionListener(e -> { openStory(VisualsUtils.askForFile(this, Lang.get("file.title"))); }); final JButton btnOpenEditor = new JButton(Lang.get("welcome.openeditor")); panel.add(btnOpenEditor, "cell 4 1"); btnOpenEditor.setIcon(new ImageIcon(Icons.getImage("Edit Property", 40))); btnOpenEditor.addActionListener(e -> { openEditor(VisualsUtils.askForFile(this, Lang.get("file.title"))); }); JButton btnChangeBackground = new JButton(Lang.get("welcome.changebackground"), new ImageIcon(Icons.getImage("Change Theme", 16))); btnChangeBackground.addActionListener(e -> { BufferedImage prev = background.getImage(); BufferedImage next; do { next = Icons.getRandomBackground(); } while (prev == next); background.setImage(next); }); welcomeContentPanel.add(btnChangeBackground, "flowx,cell 0 2,alignx left"); JButton btnWelcomepixabay = new JButton(Lang.get("welcome.pixabay"), new ImageIcon(Icons.getImage("External Link", 16))); btnWelcomepixabay.addActionListener(e -> { VisualsUtils.browse("https://pixabay.com"); }); welcomeContentPanel.add(btnWelcomepixabay, "cell 0 2"); JLabel creds = new JLabel(Lang.get("welcome.credits")); creds.setEnabled(false); welcomeContentPanel.add(creds, "cell 0 2, gapbefore 10px"); setSize((int) (830 * Icons.getScale()), (int) (480 * Icons.getScale())); setLocationRelativeTo(null); }