List of usage examples for javax.swing ImageIcon ImageIcon
public ImageIcon(byte[] imageData)
From source file:TreeNodeVector.java
public static void main(final String args[]) { UIManager.put("Tree.openIcon", new ImageIcon("yourFile.gif")); JFrame frame = new JFrame("JTreeSample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Vector<String> v1 = new TreeNodeVector<String>("Two", new String[] { "Mercury", "Venus", "Mars" }); Vector<Object> v2 = new TreeNodeVector<Object>("Three"); v2.add(System.getProperties()); v2.add(v1);//ww w . j av a 2 s . c o m Object rootNodes[] = { v1, v2 }; Vector<Object> rootVector = new TreeNodeVector<Object>("Root", rootNodes); JTree tree = new JTree(rootVector); frame.add(new JScrollPane(tree), BorderLayout.CENTER); frame.setSize(300, 300); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { Robot robot = new Robot(); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); BufferedImage image = robot.createScreenCapture(new Rectangle(d)); BufferedImage sub = image.getSubimage(0, 0, 400, 400); File f = new File("SubImage.png"); ImageIO.write(sub, "png", f); final ImageIcon im = new ImageIcon(f.toURI().toURL()); Runnable r = new Runnable() { @Override//from w ww . j a va2 s. co m public void run() { JOptionPane.showMessageDialog(null, new JLabel(im)); } }; SwingUtilities.invokeLater(r); }
From source file:DragMouseAdapter.java
public static void main(String[] args) { JFrame f = new JFrame("Icon Drag & Drop"); ImageIcon icon1 = new ImageIcon("a.png"); ImageIcon icon2 = new ImageIcon("b.png"); ImageIcon icon3 = new ImageIcon("c.png"); JButton button = new JButton(icon2); JLabel label1 = new JLabel(icon1, JLabel.CENTER); JLabel label2 = new JLabel(icon3, JLabel.CENTER); MouseListener listener = new DragMouseAdapter(); label1.addMouseListener(listener);//from w w w. j ava2s . c o m label2.addMouseListener(listener); label1.setTransferHandler(new TransferHandler("icon")); button.setTransferHandler(new TransferHandler("icon")); label2.setTransferHandler(new TransferHandler("icon")); f.setLayout(new FlowLayout()); f.add(label1); f.add(button); f.add(label2); f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { SwingUtilities.invokeLater(new Runnable() { public void run() { try { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); BufferedImage image = ImageIO.read(new URL("http://www.java2s.com/style/download.png")); f.getContentPane().add(new JLabel(new ImageIcon(dye(image, new Color(255, 0, 0, 128))))); f.pack();// w w w . j av a 2 s . c o m f.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DefaultTableModel model = new DefaultTableModel(); JTable table = new JTable(model); model.addColumn("Col1"); model.addColumn("Col2"); table.getTableHeader().getColumnModel().getColumn(1).setHeaderRenderer(new IconHeaderRenderer()); table.getColumnModel().getColumn(1).setHeaderValue(new TextAndIcon("Col2", new ImageIcon("icon.gif"))); }
From source file:Main.java
public static void main(String[] args) throws Exception { String mapUrlPath = "http://www.java2s.com/style/download.png"; URL mapUrl = new URL(mapUrlPath); BufferedImage mapImage = ImageIO.read(mapUrl); Image newMapImage = Toolkit.getDefaultToolkit() .createImage(new FilteredImageSource(mapImage.getSource(), new XorFilter())); ImageIcon mapIcon = new ImageIcon(mapImage); ImageIcon newMapIcon = new ImageIcon(newMapImage); JPanel imagePanel = new JPanel(); imagePanel.add(new JLabel(mapIcon)); imagePanel.add(new JLabel(newMapIcon)); JOptionPane.showMessageDialog(null, imagePanel); }
From source file:Main.java
public static void main(String[] args) throws Exception { String mapUrlPath = "http://www.java2s.com/style/download.png"; URL mapUrl = new URL(mapUrlPath); BufferedImage mapImage = ImageIO.read(mapUrl); Image newMapImage = Toolkit.getDefaultToolkit() .createImage(new FilteredImageSource(mapImage.getSource(), new GrayFilter())); ImageIcon mapIcon = new ImageIcon(mapImage); ImageIcon newMapIcon = new ImageIcon(newMapImage); JPanel imagePanel = new JPanel(); imagePanel.add(new JLabel(mapIcon)); imagePanel.add(new JLabel(newMapIcon)); JOptionPane.showMessageDialog(null, imagePanel); }
From source file:Main.java
public static void main(String[] args) throws Exception { String mapUrlPath = "http://www.java2s.com/style/download.png"; URL mapUrl = new URL(mapUrlPath); BufferedImage mapImage = ImageIO.read(mapUrl); Image newMapImage = Toolkit.getDefaultToolkit() .createImage(new FilteredImageSource(mapImage.getSource(), new RedBlueSwapFilter())); ImageIcon mapIcon = new ImageIcon(mapImage); ImageIcon newMapIcon = new ImageIcon(newMapImage); JPanel imagePanel = new JPanel(); imagePanel.add(new JLabel(mapIcon)); imagePanel.add(new JLabel(newMapIcon)); JOptionPane.showMessageDialog(null, imagePanel); }
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 BufferedImage image = ImageIO.read(url); int x = 50;/*w ww . j a va 2 s. co m*/ final Image crop = image.getSubimage(x, 0, image.getWidth() - x, image.getHeight()); Runnable r = new Runnable() { @Override public void run() { JPanel gui = new JPanel(); gui.add(new JLabel(new ImageIcon(image)), BorderLayout.LINE_START); gui.add(new JLabel("java2s.com")); gui.add(new JLabel(new ImageIcon(crop)), BorderLayout.LINE_END); JOptionPane.showMessageDialog(null, gui); } }; SwingUtilities.invokeLater(r); }
From source file:Main.java
public static void main(String[] args) throws Exception { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); URL url = new URL("http://www.java2s.com/style/download.png"); Image image = ImageIO.read(url); ImagePanel ip = new ImagePanel(new GridLayout(4, 4, 20, 20)); ip.setPreferredSize(new Dimension(640, 480)); f.setContentPane(ip);//from w w w . j a v a2s . c o m f.pack(); f.setVisible(true); ip.setImage(new ImageIcon(image)); }