List of usage examples for javax.swing ImageIcon getIconHeight
public int getIconHeight()
From source file:ButtonScroll.java
public ButtonScroll() { super("Scrolling Programmatically"); setSize(400, 400);//from w ww . j a va 2s. 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:FramewithComponents.java
public FramewithComponents() { super("JLayeredPane Demo"); setSize(256, 256);// www .j av a 2 s . co 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); 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:ru.codemine.pos.ui.windows.products.ProductWindow.java
@Override public void showWindow(Product product) { if (!actionListenersInit) setupActionListeners();// w w w. j ava 2 s . c o m this.product = product; setTitle(" - " + product.getName()); idField.setText(product.getId() == null ? "" : product.getId().toString()); artikulField.setText(product.getArtikul()); nameField.setText(product.getName()); barcodeField.setText(product.getBarcode()); priceField.setValue(product.getPrice()); if (product.getId() == null) { artikulField.setEditable(true); } else { artikulField.setEditable(false); } List<Store> proxedStores = storeService.getAll(); List<Store> stores = new ArrayList<>(); for (Store s : proxedStores) { stores.add(storeService.unproxyStocks(s)); } stocksTable.setModel(new ProductByStoresTableModel(product, stores)); TableColumnModel columnModel = stocksTable.getColumnModel(); columnModel.getColumn(0).setMaxWidth(10); File imgFile = new File("images/products/" + product.getArtikul() + ".jpg"); String imgPath = "images/products/default.jpg"; if (imgFile.exists() && !imgFile.isDirectory()) { imgPath = imgFile.getAbsolutePath(); } ImageIcon ico = new ImageIcon(imgPath); if (ico.getIconHeight() > 0) { Image img = ico.getImage().getScaledInstance(200, 200, Image.SCALE_SMOOTH); imagePanel.setImage(img, true); } setVisible(true); }
From source file:examples.monalisa.gui.GeneticDrawingView.java
/** * Scale an image to fit the size of the targetImageLabel. * * @param a_image the image to scale/* w ww . j a va2 s . co m*/ * @return scaled image */ public ImageIcon scaleToImageLabel(Image a_image) { ImageIcon scaled = new ImageIcon(a_image); if (scaled.getIconHeight() > targetImageLabel.getHeight()) { scaled = new ImageIcon(a_image.getScaledInstance(-1, targetImageLabel.getHeight(), Image.SCALE_FAST)); } if (scaled.getIconWidth() > targetImageLabel.getWidth()) { scaled = new ImageIcon(a_image.getScaledInstance(targetImageLabel.getWidth(), -1, Image.SCALE_FAST)); } return scaled; }
From source file:examples.gp.monalisa.gui.GeneticDrawingView.java
/** * Scale an image to fit the size of the targetImageLabel. *///from w w w. ja va 2s.com public ImageIcon scaleToImageLabel(Image image) { ImageIcon scaled = new ImageIcon(image); if (scaled.getIconHeight() > targetImageLabel.getHeight()) { scaled = new ImageIcon(image.getScaledInstance(-1, targetImageLabel.getHeight(), Image.SCALE_FAST)); } if (scaled.getIconWidth() > targetImageLabel.getWidth()) { scaled = new ImageIcon(image.getScaledInstance(targetImageLabel.getWidth(), -1, Image.SCALE_FAST)); } return scaled; }
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:gd.gui.GeneticDrawingView.java
/** * Scale an image to fit the size of the targetImageLabel. *//*w ww . j a va2 s .c o m*/ public ImageIcon scaleToImageLabel(Image image) { ImageIcon scaled = new ImageIcon(image); if (scaled.getIconHeight() > targetImageLabel.getHeight()) { scaled = new ImageIcon(image.getScaledInstance(-1, targetImageLabel.getHeight(), Image.SCALE_FAST)); } if (scaled.getIconWidth() > targetImageLabel.getWidth()) { scaled = new ImageIcon(image.getScaledInstance(targetImageLabel.getWidth(), -1, Image.SCALE_FAST)); } return scaled; }
From source file:edu.ku.brc.specify.tasks.subpane.wb.ImageFrame.java
/** * Makes sure the image can be read and it is not corrupted. * @param srcFile the full path to the image * @return true if ok/*from w w w . ja va2 s .c o m*/ */ public static boolean testImageFile(final String srcFile) { try { byte[] bytes = GraphicsUtils.readImage(srcFile); if (bytes != null) { ImageIcon testIcon = new ImageIcon(bytes); //System.err.println(testIcon.getIconHeight()+" "+testIcon.getIconWidth()); // this image file is corrupted or a format that we cannot display return testIcon.getIconHeight() > 0 && testIcon.getIconWidth() > 0; } } catch (Exception ex) { ex.printStackTrace(); } return false; }
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);/*from w w w. ja va 2s .co 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 . j a va2 s. co 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()); }