List of usage examples for javax.swing ImageIcon getIconWidth
public int getIconWidth()
From source file:components.ImagePreview.java
public void loadImage() { if (file == null) { thumbnail = null;//from www . j a v a2 s . co m return; } //Don't use createImageIcon (which is a wrapper for getResource) //because the image we're trying to load is probably not one //of this program's own resources. ImageIcon tmpIcon = new ImageIcon(file.getPath()); if (tmpIcon != null) { if (tmpIcon.getIconWidth() > 90) { thumbnail = new ImageIcon(tmpIcon.getImage().getScaledInstance(90, -1, Image.SCALE_DEFAULT)); } else { //no need to miniaturize thumbnail = tmpIcon; } } }
From source file:Main.java
public Main() { super("JLayeredPane Demo"); setSize(256, 256);//from w w w . j a v a 2 s. c o m JPanel content = new JPanel(); content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS)); content.setOpaque(false); JLabel label1 = new JLabel("Username:"); label1.setForeground(Color.white); content.add(label1); JTextField field = new JTextField(15); content.add(field); JLabel label2 = new JLabel("Password:"); label2.setForeground(Color.white); content.add(label2); JPasswordField fieldPass = new JPasswordField(15); content.add(fieldPass); setLayout(new FlowLayout()); add(content); ((JPanel) getContentPane()).setOpaque(false); ImageIcon earth = new ImageIcon("largeJava2sLogo.png"); JLabel backlabel = new JLabel(earth); getLayeredPane().add(backlabel, new Integer(Integer.MIN_VALUE)); backlabel.setBounds(0, 0, earth.getIconWidth(), earth.getIconHeight()); super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); }
From source file:FramewithComponents.java
public FramewithComponents() { super("JLayeredPane Demo"); setSize(256, 256);//from w ww.j a va2 s . c om JPanel content = new JPanel(); content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS)); content.setOpaque(false); JLabel label1 = new JLabel("Username:"); label1.setForeground(Color.white); content.add(label1); JTextField field = new JTextField(15); content.add(field); JLabel label2 = new JLabel("Password:"); label2.setForeground(Color.white); content.add(label2); JPasswordField fieldPass = new JPasswordField(15); content.add(fieldPass); getContentPane().setLayout(new FlowLayout()); getContentPane().add(content); ((JPanel) getContentPane()).setOpaque(false); ImageIcon earth = new ImageIcon("largeJava2sLogo.png"); JLabel backlabel = new JLabel(earth); getLayeredPane().add(backlabel, new Integer(Integer.MIN_VALUE)); backlabel.setBounds(0, 0, earth.getIconWidth(), earth.getIconHeight()); WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(l); setVisible(true); }
From source file:FilterSample.java
public void propertyChange(PropertyChangeEvent changeEvent) { String changeName = changeEvent.getPropertyName(); if (changeName.equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY)) { File file = (File) changeEvent.getNewValue(); if (file != null) { ImageIcon icon = new ImageIcon(file.getPath()); if (icon.getIconWidth() > PREFERRED_WIDTH) { icon = new ImageIcon( icon.getImage().getScaledInstance(PREFERRED_WIDTH, -1, Image.SCALE_DEFAULT)); if (icon.getIconHeight() > PREFERRED_HEIGHT) { icon = new ImageIcon( icon.getImage().getScaledInstance(-1, PREFERRED_HEIGHT, Image.SCALE_DEFAULT)); }/*from w w w.j av a 2 s . co m*/ } setIcon(icon); } } }
From source file:FileChooserTest.java
/** * Constructs an ImagePreviewer.// w w w . j a va2 s .co m * @param chooser the file chooser whose property changes trigger an image change in this * previewer */ public ImagePreviewer(JFileChooser chooser) { setPreferredSize(new Dimension(100, 100)); setBorder(BorderFactory.createEtchedBorder()); chooser.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (event.getPropertyName() == JFileChooser.SELECTED_FILE_CHANGED_PROPERTY) { // the user has selected a new file File f = (File) event.getNewValue(); if (f == null) { setIcon(null); return; } // read the image into an icon ImageIcon icon = new ImageIcon(f.getPath()); // if the icon is too large to fit, scale it if (icon.getIconWidth() > getWidth()) icon = new ImageIcon( icon.getImage().getScaledInstance(getWidth(), -1, Image.SCALE_DEFAULT)); setIcon(icon); } } }); }
From source file:SampleDesktop.java
protected void loadBackgroundImage() { ImageIcon icon = new ImageIcon("images/matterhorn.gif"); JLabel l = new JLabel(icon); l.setBounds(0, 0, icon.getIconWidth(), icon.getIconHeight()); // Place the image in the lowest possible layer so nothing // can ever be painted under it. desk.add(l, new Integer(Integer.MIN_VALUE)); }
From source file:ButtonScroll.java
public ButtonScroll() { super("Scrolling Programmatically"); setSize(400, 400);/*from w w w . j av a 2 s .co m*/ getContentPane().setLayout(new BorderLayout()); ImageIcon shuttle = new ImageIcon("largeJava2sLogo.GIF"); pgVertical = shuttle.getIconHeight() / 5; pgHorzontal = shuttle.getIconWidth() / 5; JLabel lbl = new JLabel(shuttle); viewport = new JViewport(); viewport.setView(lbl); viewport.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { enableButtons(ButtonScroll.this.viewport.getViewPosition()); } }); getContentPane().add(viewport, BorderLayout.CENTER); JPanel pv = new JPanel(new BorderLayout()); upButton = createButton("up", 'u'); ActionListener lst = new ActionListener() { public void actionPerformed(ActionEvent e) { movePanel(0, -1); } }; upButton.addActionListener(lst); pv.add(upButton, BorderLayout.NORTH); downButton = createButton("down", 'd'); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { movePanel(0, 1); } }; downButton.addActionListener(lst); pv.add(downButton, BorderLayout.SOUTH); getContentPane().add(pv, BorderLayout.EAST); JPanel ph = new JPanel(new BorderLayout()); leftButton = createButton("left", 'l'); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { movePanel(-1, 0); } }; leftButton.addActionListener(lst); ph.add(leftButton, BorderLayout.WEST); rightButton = createButton("right", 'r'); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { movePanel(1, 0); } }; rightButton.addActionListener(lst); ph.add(rightButton, BorderLayout.EAST); getContentPane().add(ph, BorderLayout.SOUTH); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); setVisible(true); movePanel(0, 0); }
From source file:JSplash.java
private void init() { JPanel pnlImage = new JPanel(); ImageIcon image = new ImageIcon(getClass().getResource("img/logo.jpg")); JLabel lblBack = new JLabel(image); Border raisedbevel = BorderFactory.createRaisedBevelBorder(); Border loweredbevel = BorderFactory.createLoweredBevelBorder(); lblBack.setBounds(0, 0, image.getIconWidth(), image.getIconHeight()); getLayeredPane().add(lblBack, new Integer(Integer.MIN_VALUE)); pnlImage.setLayout(null);// w w w . java 2 s . c o m pnlImage.setOpaque(false); pnlImage.setBorder(BorderFactory.createCompoundBorder(raisedbevel, loweredbevel)); pnlImage.add(this.lblVersion); this.lblVersion.setForeground(Color.white); this.lblVersion.setFont(new Font("Dialog", Font.PLAIN, 12)); this.lblVersion.setBounds(15, 69, 120, 20); setContentPane(pnlImage); setSize(image.getIconWidth(), image.getIconHeight()); }
From source file:examples.gp.monalisa.gui.GeneticDrawingView.java
public GeneticDrawingView(SingleFrameApplication app) { super(app);/*from w ww .ja v a 2 s. c o m*/ initComponents(); ResourceMap resourceMap = getResourceMap(); ImageIcon imageIcon = resourceMap.getImageIcon("targetImageLabel.icon"); targetImage = new BufferedImage(imageIcon.getIconWidth(), imageIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); imageIcon.paintIcon(null, targetImage.getGraphics(), 0, 0); fittestDrawingView = new FittestDrawingView(); fittestDrawingView.setVisible(false); fittestDrawingView.setSize(targetImage.getWidth(), targetImage.getHeight()); }
From source file:gd.gui.GeneticDrawingView.java
public GeneticDrawingView(SingleFrameApplication app) { super(app);//from w w w . ja v a 2 s . c o m initComponents(); ResourceMap resourceMap = getResourceMap(); ImageIcon imageIcon = resourceMap.getImageIcon("targetImageLabel.icon"); targetImage = new BufferedImage(imageIcon.getIconWidth(), imageIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); imageIcon.paintIcon(null, targetImage.getGraphics(), 0, 0); ProblemInstance.currentImage = targetImage; ProblemInstance.view = this; fittestDrawingView = new FittestDrawingView(); fittestDrawingView.setVisible(false); fittestDrawingView.setSize(targetImage.getWidth(), targetImage.getHeight()); try { startEvolution(); } catch (InvalidConfigurationException e) { e.printStackTrace(); } }