List of usage examples for javax.swing ImageIcon ImageIcon
public ImageIcon(byte[] imageData)
From source file:Main.java
public static void main(String[] arg) throws Exception { Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize(); Robot robot = new Robot(); BufferedImage image = robot//from ww w. j a va 2 s. com .createScreenCapture(new Rectangle(0, 0, (int) screenDim.getWidth(), (int) screenDim.getHeight())); JWindow window = new JWindow(new JFrame()); window.getContentPane().setLayout(new BorderLayout()); window.getContentPane().add(BorderLayout.CENTER, new JLabel(new ImageIcon(image))); window.pack(); window.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { JFrame f = new JFrame(Main.class.getSimpleName()); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); BufferedImage bi = ImageIO.read(new URL("http://www.java2s.com/style/download.png")); JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel(new ImageIcon(bi)); panel.add(label);//from w w w . j a va 2s. c om MouseMotionListener doScrollRectToVisible = new MouseMotionAdapter() { @Override public void mouseDragged(MouseEvent e) { Rectangle r = new Rectangle(e.getX(), e.getY(), 1, 1); ((JPanel) e.getSource()).scrollRectToVisible(r); } }; panel.addMouseMotionListener(doScrollRectToVisible); panel.setAutoscrolls(true); f.add(new JScrollPane(panel)); f.pack(); f.setSize(f.getWidth() / 2, f.getHeight() / 2); f.setVisible(true); }
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 GrayToColorFilter(Color.red))); 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:BorderLayoutExample.java
public static void main(String[] args) { JFrame f = new JFrame(); JMenuBar menubar = new JMenuBar(); JMenu file = new JMenu("File"); menubar.add(file);/*w ww . java 2 s . co m*/ f.setJMenuBar(menubar); JToolBar toolbar = new JToolBar(); toolbar.setFloatable(false); JButton bexit = new JButton(new ImageIcon("exit.png")); bexit.setBorder(new EmptyBorder(0, 0, 0, 0)); toolbar.add(bexit); f.add(toolbar, BorderLayout.NORTH); JToolBar vertical = new JToolBar(JToolBar.VERTICAL); vertical.setFloatable(false); vertical.setMargin(new Insets(10, 5, 5, 5)); JButton selectb = new JButton(new ImageIcon("a.png")); selectb.setBorder(new EmptyBorder(3, 0, 3, 0)); JButton freehandb = new JButton(new ImageIcon("b.png")); freehandb.setBorder(new EmptyBorder(3, 0, 3, 0)); JButton shapeedb = new JButton(new ImageIcon("c.png")); shapeedb.setBorder(new EmptyBorder(3, 0, 3, 0)); vertical.add(selectb); vertical.add(freehandb); vertical.add(shapeedb); f.add(vertical, BorderLayout.WEST); f.add(new JTextArea(), BorderLayout.CENTER); JLabel statusbar = new JLabel(" Statusbar"); statusbar.setPreferredSize(new Dimension(-1, 22)); statusbar.setBorder(LineBorder.createGrayLineBorder()); f.add(statusbar, BorderLayout.SOUTH); f.setSize(350, 300); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws IOException { String path = "C:/Pictures/"; JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); File folder = new File(path); File[] listOfFiles = folder.listFiles(); DefaultListModel listModel = new DefaultListModel(); int count = 0; for (int i = 0; i < listOfFiles.length; i++) { String name = listOfFiles[i].toString(); if (name.endsWith("jpg")) { ImageIcon ii = new ImageIcon(ImageIO.read(listOfFiles[i])); listModel.add(count++, ii);/* w w w .j a va 2s .c o m*/ } } JList lsm = new JList(listModel); lsm.setVisibleRowCount(1); frame.add(new JScrollPane(lsm)); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { Runnable r = new Runnable() { @Override/*from w ww . ja va2s. c om*/ public void run() { JPanel gui = new JPanel(); final AnimatedImage[] tiles = new AnimatedImage[2]; for (int ii = 0; ii < tiles.length; ii++) { tiles[ii] = new AnimatedImage(); gui.add(new JLabel(new ImageIcon(tiles[ii]))); } ActionListener listener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { for (int i = 0; i < tiles.length; i++) { tiles[i].paintImage(); gui.repaint(); } } }; Timer timer = new Timer(50, listener); timer.start(); JOptionPane.showMessageDialog(null, gui); timer.stop(); } }; SwingUtilities.invokeLater(r); }
From source file:Main.java
public static void main(String[] args) throws IOException { BufferedImage large = ImageIO.read(new File("images/a.jpg")); BufferedImage small = ImageIO.read(new File("images/b.jpg")); int w = large.getWidth(); int h = large.getHeight(); int type = BufferedImage.TYPE_INT_RGB; BufferedImage image = new BufferedImage(w, h, type); Graphics2D g2 = image.createGraphics(); g2.drawImage(large, 0, 0, null);/*from w w w . ja va 2s .c o m*/ g2.drawImage(small, 10, 10, null); g2.dispose(); ImageIO.write(image, "jpg", new File("new.jpg")); JOptionPane.showMessageDialog(null, new ImageIcon(image), "", JOptionPane.PLAIN_MESSAGE); }
From source file:MainClass.java
public static void main(String args[]) { JFrame frame = new JFrame("Drag Image"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Icon icon = new ImageIcon("image.jpg"); JLabel label = new JLabel(icon); label.setTransferHandler(new ImageSelection()); MouseListener listener = new MouseAdapter() { public void mousePressed(MouseEvent me) { JComponent comp = (JComponent) me.getSource(); TransferHandler handler = comp.getTransferHandler(); handler.exportAsDrag(comp, me, TransferHandler.COPY); }//from w w w.j a va 2 s. c o m }; label.addMouseListener(listener); frame.add(new JScrollPane(label), BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:JTextPaneWithIcon.java
public static void main(String args[]) { JFrame frame = new JFrame("TextPane Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); StyleContext context = new StyleContext(); StyledDocument document = new DefaultStyledDocument(context); Style labelStyle = context.getStyle(StyleContext.DEFAULT_STYLE); Icon icon = new ImageIcon("yourFile.gif"); JLabel label = new JLabel(icon); StyleConstants.setComponent(labelStyle, label); try {/*w w w . j av a2 s . c om*/ document.insertString(document.getLength(), "Ignored", labelStyle); } catch (BadLocationException badLocationException) { System.err.println("Oops"); } JTextPane textPane = new JTextPane(document); textPane.setEditable(false); JScrollPane scrollPane = new JScrollPane(textPane); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:ImageBorderHack.java
public static void main(String[] args) { JFrame frame = new JFrame("Hack #59: Image Border"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); JButton button = new JButton("Image Border Test"); panel.add(button);/*from www .j a v a2 s .c o m*/ ImageBorder image_border = new ImageBorder(new ImageIcon("upperLeft.png").getImage(), new ImageIcon("upper.png").getImage(), new ImageIcon("upperRight.png").getImage(), new ImageIcon("leftCenter.png").getImage(), new ImageIcon("rightCenter.png").getImage(), new ImageIcon("bottomLeft.png").getImage(), new ImageIcon("bottomCenter.png").getImage(), new ImageIcon("bottomRight.png").getImage()); panel.setBorder(image_border); frame.getContentPane().add(panel); frame.pack(); // frame.setSize(200,200); frame.setVisible(true); }