List of usage examples for javax.swing ImageIcon ImageIcon
public ImageIcon(byte[] imageData)
From source file:Submenu.java
public static void main(String[] args) { JFrame f = new JFrame(); JMenuBar menubar = new JMenuBar(); ImageIcon iconNew = new ImageIcon("new.png"); ImageIcon iconOpen = new ImageIcon("open.png"); ImageIcon iconSave = new ImageIcon("save.png"); ImageIcon iconClose = new ImageIcon("exit.png"); JMenu file = new JMenu("File"); JMenu imp = new JMenu("Import"); JMenuItem fileNew = new JMenuItem("New", iconNew); JMenuItem fileOpen = new JMenuItem("Open", iconOpen); JMenuItem fileSave = new JMenuItem("Save", iconSave); JMenuItem fileClose = new JMenuItem("Close", iconClose); file.setMnemonic(KeyEvent.VK_F); imp.setMnemonic(KeyEvent.VK_M); JMenuItem newsf = new JMenuItem("Import newsfeed list..."); JMenuItem bookm = new JMenuItem("Import bookmarks..."); JMenuItem mail = new JMenuItem("Import mail..."); imp.add(newsf);/*from w w w.ja v a 2s . co m*/ imp.add(bookm); imp.add(mail); fileNew.setMnemonic(KeyEvent.VK_N); fileNew.setMnemonic(KeyEvent.VK_O); fileSave.setMnemonic(KeyEvent.VK_S); fileClose.setMnemonic(KeyEvent.VK_C); fileClose.setToolTipText("Exit application"); fileClose.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, ActionEvent.CTRL_MASK)); fileClose.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); file.add(fileNew); file.add(fileOpen); file.add(fileSave); file.addSeparator(); file.add(imp); file.addSeparator(); file.add(fileClose); menubar.add(file); f.setJMenuBar(menubar); f.setSize(360, 250); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:AdjustmentTest.java
public static void main(String args[]) { JFrame frame = new JFrame(); Container contentPane = frame.getContentPane(); Icon icon = new ImageIcon("java2s.gif"); JButton b = new JButton(icon); JScrollPane pane = new JScrollPane(b); AdjustmentListener hListener = new AdjustmentListener() { public void adjustmentValueChanged(AdjustmentEvent e) { System.out.println("Horizontal: "); dumpInfo(e);/* ww w .j av a2 s. co m*/ } }; JScrollBar hBar = pane.getHorizontalScrollBar(); hBar.addAdjustmentListener(hListener); AdjustmentListener vListener = new AdjustmentListener() { public void adjustmentValueChanged(AdjustmentEvent e) { System.out.println("Vertical: "); dumpInfo(e); } }; JScrollBar vBar = pane.getVerticalScrollBar(); vBar.addAdjustmentListener(vListener); contentPane.add(pane, BorderLayout.CENTER); frame.setSize(300, 200); frame.show(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { final Action action = new AbstractAction("Action Name") { {//w w w .ja v a 2 s .c om putValue(Action.SHORT_DESCRIPTION, "Tool Tip Text"); putValue(Action.LONG_DESCRIPTION, "Help Text"); Icon icon = new ImageIcon("icon.gif"); putValue(Action.SMALL_ICON, icon); putValue(Action.MNEMONIC_KEY, new Integer(java.awt.event.KeyEvent.VK_A)); putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control F2")); } public void actionPerformed(ActionEvent evt) { System.out.println("action"); } }; JButton button = new JButton(action); }
From source file:Main.java
public static void main(String[] args) throws Exception { URL url = new URL("http://www.java2s.com/style/download.png"); final Image img = ImageIO.read(url); Runnable r = new Runnable() { @Override/*from w w w. jav a 2 s .c o m*/ public void run() { JOptionPane.showMessageDialog(null, new JLabel(new ImageIcon(img))); } }; SwingUtilities.invokeLater(r); }
From source file:Main.java
public static void main(String[] argv) throws Exception { File sourceimage = new File("source.gif"); Image image = ImageIO.read(sourceimage); JFrame frame = new JFrame(); JLabel label = new JLabel(new ImageIcon(image)); frame.getContentPane().add(label, BorderLayout.CENTER); frame.pack();/*from www . ja v a 2 s .com*/ frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Tick Slider"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JSlider jSliderOne = new JSlider(); jSliderOne.setPaintLabels(true);/*from w w w . j a va 2 s. c o m*/ Hashtable<Integer, JLabel> table = new Hashtable<Integer, JLabel>(); table.put(0, new JLabel(new ImageIcon("yourFile.gif"))); table.put(10, new JLabel("Ten")); table.put(25, new JLabel("Twenty-Five")); table.put(34, new JLabel("Thirty-Four")); table.put(52, new JLabel("Fifty-Two")); table.put(70, new JLabel("Seventy")); table.put(82, new JLabel("Eighty-Two")); jSliderOne.setLabelTable(table); frame.add(jSliderOne, BorderLayout.NORTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { InputStream is = new BufferedInputStream(new FileInputStream("s.gif")); Image image = ImageIO.read(is); JFrame frame = new JFrame(); JLabel label = new JLabel(new ImageIcon(image)); frame.getContentPane().add(label, BorderLayout.CENTER); frame.pack();// ww w . j a va2 s. c o m frame.setVisible(true); }
From source file:AddingButtonWithActionListener.java
public static void main(String[] a) { JFrame frame = new JFrame(); JOptionPane optionPane = new JOptionPane(); optionPane.setMessage("I got an icon and a text label"); optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE); Icon icon = new ImageIcon("yourFile.gif"); JButton jButton = getButton(optionPane, "OK", icon); optionPane.setOptions(new Object[] { jButton }); JDialog dialog = optionPane.createDialog(frame, "Icon/Text Button"); dialog.setVisible(true);/*from w w w . ja v a 2 s . c o m*/ }
From source file:ButtonCornerSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Cornering Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Icon acrossLogo = new ImageIcon("logo-across.jpg"); Icon downLogo = new ImageIcon("logo-down.jpg"); Icon bookCover = new ImageIcon("puzzlebook.jpg"); JLabel columnLabel = new JLabel(acrossLogo); JLabel rowLabel = new JLabel(downLogo); JLabel coverLabel = new JLabel(bookCover); JButton button = new JButton("+"); button.setFont(new Font("Monospaced", Font.PLAIN, 8)); JScrollPane scrollPane = new JScrollPane(coverLabel); scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, button); scrollPane.setColumnHeaderView(columnLabel); scrollPane.setRowHeaderView(rowLabel); ActionListener actionListener = new JScrollPaneToTopAction(scrollPane); button.addActionListener(actionListener); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 200);//from w w w . java 2 s . c o m frame.setVisible(true); }
From source file:SimpleToolbar.java
public static void main(String[] args) { JFrame f = new JFrame(); JMenuBar menubar = new JMenuBar(); JMenu file = new JMenu("File"); menubar.add(file);//from ww w .ja v a 2 s.c om f.setJMenuBar(menubar); JToolBar toolbar = new JToolBar(); ImageIcon icon = new ImageIcon("exit.png"); JButton exit = new JButton(icon); toolbar.add(exit); exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); f.add(toolbar, BorderLayout.NORTH); f.setSize(300, 200); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }