List of usage examples for javax.swing ImageIcon ImageIcon
public ImageIcon(byte[] imageData)
From source file:BasicDraw.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; AffineTransform tx = new AffineTransform(); double scalex = .5; double scaley = 1; tx.scale(scalex, scaley);/*from w w w . jav a2 s .c om*/ g2d.setTransform(tx); g2d.drawImage(new ImageIcon("a.png").getImage(), tx, this); }
From source file:Faces.java
public void init() { faces = new Icon[] { new ImageIcon(getClass().getResource("Face0.gif")), new ImageIcon(getClass().getResource("Face1.gif")), new ImageIcon(getClass().getResource("Face2.gif")), new ImageIcon(getClass().getResource("Face3.gif")), new ImageIcon(getClass().getResource("Face4.gif")), }; jb = new JButton("JButton", faces[3]); Container cp = getContentPane(); cp.setLayout(new FlowLayout()); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (mad) { jb.setIcon(faces[3]);/*from w ww .ja v a 2 s.c o m*/ mad = false; } else { jb.setIcon(faces[0]); mad = true; } jb.setVerticalAlignment(JButton.TOP); jb.setHorizontalAlignment(JButton.LEFT); } }); jb.setRolloverEnabled(true); jb.setRolloverIcon(faces[1]); jb.setPressedIcon(faces[2]); jb.setDisabledIcon(faces[4]); jb.setToolTipText("Yow!"); cp.add(jb); jb2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (jb.isEnabled()) { jb.setEnabled(false); jb2.setText("Enable"); } else { jb.setEnabled(true); jb2.setText("Disable"); } } }); cp.add(jb2); }
From source file:SimpleInternalFrame.java
public SimpleInternalFrame() { super(""); setSize(500, 400);//from w w w .j a va2s . c o m desktop = new JDesktopPane(); desktop.setOpaque(true); add(desktop, BorderLayout.CENTER); internalFrame = new JInternalFrame("Meow", true, true, true, true); internalFrame.setBounds(50, 50, 200, 100); internalFrame.getContentPane().add(new JLabel(new ImageIcon("1.jpg"))); internalFrame.setVisible(true); desktop.add(internalFrame, new Integer(1)); }
From source file:me.ryandowling.Utils.java
public static Image getImage(String path) { URL url = System.class.getResource(path); if (url == null) { System.err.println("Unable to load image: " + path); }//from w w w. ja va 2s . c om return new ImageIcon(url).getImage(); }
From source file:StylesExample8.java
public static void createDocumentStyles(StyleContext sc) { Style defaultStyle = sc.getStyle(StyleContext.DEFAULT_STYLE); // Create and add the main document style Style mainStyle = sc.addStyle(mainStyleName, defaultStyle); StyleConstants.setLeftIndent(mainStyle, 16); StyleConstants.setRightIndent(mainStyle, 16); StyleConstants.setFirstLineIndent(mainStyle, 16); StyleConstants.setFontFamily(mainStyle, "serif"); StyleConstants.setFontSize(mainStyle, 12); // Create and add the constant width style Style cwStyle = sc.addStyle(charStyleName, null); StyleConstants.setFontFamily(cwStyle, "monospaced"); StyleConstants.setForeground(cwStyle, Color.green); // Create and add the heading style Style heading2Style = sc.addStyle(heading2StyleName, null); StyleConstants.setForeground(heading2Style, Color.red); StyleConstants.setFontSize(heading2Style, 16); StyleConstants.setFontFamily(heading2Style, "serif"); StyleConstants.setBold(heading2Style, true); StyleConstants.setLeftIndent(heading2Style, 8); StyleConstants.setFirstLineIndent(heading2Style, 0); // Create and add the Component style Class thisClass = StylesExample8.class; URL url = thisClass.getResource("java2s.gif"); ImageIcon icon = new ImageIcon(url); JLabel comp = new JLabel("Displaying text with attributes", icon, JLabel.CENTER); comp.setVerticalTextPosition(JLabel.BOTTOM); comp.setHorizontalTextPosition(JLabel.CENTER); comp.setFont(new Font("serif", Font.BOLD | Font.ITALIC, 14)); Style componentStyle = sc.addStyle(componentStyleName, null); StyleConstants.setComponent(componentStyle, comp); // The paragraph style for the component Style compParagraphStyle = sc.addStyle(compParaName, null); StyleConstants.setSpaceAbove(compParagraphStyle, (float) 16.0); }
From source file:TextPaneElements.java
public static void createDocumentStyles(StyleContext sc) { Style defaultStyle = sc.getStyle(StyleContext.DEFAULT_STYLE); // Create and add the main document style Style mainStyle = sc.addStyle(mainStyleName, defaultStyle); StyleConstants.setLeftIndent(mainStyle, 16); StyleConstants.setRightIndent(mainStyle, 16); StyleConstants.setFirstLineIndent(mainStyle, 16); StyleConstants.setFontFamily(mainStyle, "serif"); StyleConstants.setFontSize(mainStyle, 12); // Create and add the constant width style Style cwStyle = sc.addStyle(charStyleName, null); StyleConstants.setFontFamily(cwStyle, "monospaced"); StyleConstants.setForeground(cwStyle, Color.green); // Create and add the heading style Style heading2Style = sc.addStyle(heading2StyleName, null); StyleConstants.setForeground(heading2Style, Color.red); StyleConstants.setFontSize(heading2Style, 16); StyleConstants.setFontFamily(heading2Style, "serif"); StyleConstants.setBold(heading2Style, true); StyleConstants.setLeftIndent(heading2Style, 8); StyleConstants.setFirstLineIndent(heading2Style, 0); // Create and add the Component style Class thisClass = TextPaneElements.class; URL url = thisClass.getResource("java2s.gif"); ImageIcon icon = new ImageIcon(url); JLabel comp = new JLabel("Displaying text with attributes", icon, JLabel.CENTER); comp.setVerticalTextPosition(JLabel.BOTTOM); comp.setHorizontalTextPosition(JLabel.CENTER); comp.setFont(new Font("serif", Font.BOLD | Font.ITALIC, 14)); Style componentStyle = sc.addStyle(componentStyleName, null); StyleConstants.setComponent(componentStyle, comp); // The paragraph style for the component Style compParagraphStyle = sc.addStyle(compParaName, null); StyleConstants.setSpaceAbove(compParagraphStyle, (float) 16.0); }
From source file:ThumbnailTools.java
public ThumbnailTools(String fileName) { image = new ImageIcon(fileName); }
From source file:com.isencia.passerelle.hmi.action.ModelStopper.java
public ModelStopper(final HMIBase base) { super(base, HMIMessages.getString(HMIMessages.MENU_STOP), new ImageIcon(HMIBase.class.getResource("resources/terminate.gif"))); }
From source file:Main.java
public static ImageIcon createImageIcon(Class<?> bezugsklasse, String path, int width, int height) { final URL imgURL = bezugsklasse.getResource(path); if (imgURL != null) { return new ImageIcon( new ImageIcon(imgURL).getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH)); }/*from w w w .j a v a 2 s. c o m*/ System.err.println("Couldn't find file: " + path); return null; }
From source file:ImagePanel.java
public void setImage(String imageFile) { image = new ImageIcon(imageFile); updatePrefSize(); }