List of usage examples for javax.swing ImageIcon getImage
@Transient
public Image getImage()
Image
. From source file:dictionary.GUI.GUI_Main.java
/** * Creates new form GUI/*w ww. j av a2s .c o m*/ * * @throws java.io.FileNotFoundException */ public GUI_Main() throws FileNotFoundException, IOException { dic = dicEV; initComponents(); //SetIcon cho frame ImageIcon icon = new ImageIcon("src/dictionary/images/find.png"); Image image = icon.getImage(); this.setIconImage(image); fieldWord.requestFocus(); }
From source file:com.proyecto.vista.MantenimientoBien.java
private void tblbienesMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblbienesMouseReleased // TODO add your handling code here: if (evt.getClickCount() == 1) { int fila = tblbienes.getSelectedRow(); this.bien = lista.get(fila); try {/*from www . j a va2 s . com*/ nombreField.setText(BeanUtils.getProperty(bien, "nombre")); descripcionField.setText(BeanUtils.getProperty(bien, "descripcion")); fotoField.setText(BeanUtils.getProperty(bien, "foto")); ImageIcon fot = new ImageIcon(fotoField.getText()); Icon icono = new ImageIcon(fot.getImage().getScaledInstance(fotoLbl.getWidth(), fotoLbl.getHeight(), Image.SCALE_DEFAULT)); fotoLbl.setIcon(icono); // cmbClase.setSelectedItem(bien.getClase()); claseField.setText(bien.getClase().getNombre()); listarCamposMod(bien); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { Logger.getLogger(MantenimientoClase.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.proyecto.vista.MantenimientoBien.java
private void btnmodificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnmodificarActionPerformed // TODO add your handling code here: accion = Controlador.MODIFICAR;/*from w ww.j a va 2 s . com*/ // cargarCombo(); int fila = this.tblbienes.getSelectedRow(); if (fila != -1) { FormularioUtil.activarComponente(panelDatos, true); FormularioUtil.activarComponente(panelOpciones, false); FormularioUtil.activarComponente(panelGuardar, true); claseField.setEditable(false); fotoField.setEditable(false); accion = Controlador.MODIFICAR; bienControlador.setSeleccionado(lista.get(fila)); Bien bien = bienControlador.getSeleccionado(); try { nombreField.setText(BeanUtils.getProperty(bien, "nombre")); descripcionField.setText(BeanUtils.getProperty(bien, "descripcion")); fotoField.setText(BeanUtils.getProperty(bien, "foto")); ImageIcon fot = new ImageIcon(fotoField.getText()); Icon icono = new ImageIcon(fot.getImage().getScaledInstance(fotoLbl.getWidth(), fotoLbl.getHeight(), Image.SCALE_DEFAULT)); fotoLbl.setIcon(icono); // cmbClase.setSelectedItem(bien.getClase()); claseField.setText(bien.getClase().getNombre()); listarCamposMod(bien); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { Logger.getLogger(MantenimientoClase.class.getName()).log(Level.SEVERE, null, ex); } } else { JOptionPane.showMessageDialog(null, "Debe seleccionar un Bien", "Mensaje del Sistema", JOptionPane.ERROR_MESSAGE); } }
From source file:LayeredPaneDemo4.java
public LayeredPaneDemo4() { super("Custom MDI: Part V"); setSize(570, 400);/*from w w w. j av a 2 s . c o m*/ getContentPane().setBackground(new Color(244, 232, 152)); setLayeredPane(new MDIPane()); ImageIcon ii = new ImageIcon("earth.jpg"); InnerFrame[] frames = new InnerFrame[5]; for (int i = 0; i < 5; i++) { frames[i] = new InnerFrame("InnerFrame " + i); frames[i].setBounds(50 + i * 20, 50 + i * 20, 200, 200); frames[i].getContentPane().add(new JScrollPane(new JLabel(ii))); getLayeredPane().add(frames[i]); } WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; Dimension dim = getToolkit().getScreenSize(); setLocation(dim.width / 2 - getWidth() / 2, dim.height / 2 - getHeight() / 2); ImageIcon image = new ImageIcon("spiral.gif"); setIconImage(image.getImage()); addWindowListener(l); setVisible(true); }
From source file:com.xmage.launcher.XMageLauncher.java
private XMageLauncher() { locale = Locale.getDefault(); //locale = new Locale("it", "IT"); messages = ResourceBundle.getBundle("MessagesBundle", locale); localize();// www . j av a2 s . com serverConsole = new XMageConsole("XMage Server console"); clientConsole = new XMageConsole("XMage Client console"); frame = new JFrame(messages.getString("frameTitle") + " " + Config.getVersion()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setPreferredSize(new Dimension(800, 500)); frame.setResizable(false); createToolbar(); ImageIcon icon = new ImageIcon(XMageLauncher.class.getResource("/icon-mage-flashed.png")); frame.setIconImage(icon.getImage()); Random r = new Random(); int imageNum = 1 + r.nextInt(17); ImageIcon background = new ImageIcon(new ImageIcon( XMageLauncher.class.getResource("/backgrounds/" + Integer.toString(imageNum) + ".jpg")).getImage() .getScaledInstance(800, 480, Image.SCALE_SMOOTH)); mainPanel = new JLabel(background) { @Override public Dimension getPreferredSize() { Dimension size = super.getPreferredSize(); Dimension lmPrefSize = getLayout().preferredLayoutSize(this); size.width = Math.max(size.width, lmPrefSize.width); size.height = Math.max(size.height, lmPrefSize.height); return size; } }; mainPanel.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { grabPoint = e.getPoint(); mainPanel.getComponentAt(grabPoint); } }); mainPanel.addMouseMotionListener(new MouseMotionAdapter() { @Override public void mouseDragged(MouseEvent e) { // get location of Window int thisX = frame.getLocation().x; int thisY = frame.getLocation().y; // Determine how much the mouse moved since the initial click int xMoved = (thisX + e.getX()) - (thisX + grabPoint.x); int yMoved = (thisY + e.getY()) - (thisY + grabPoint.y); // Move window to this position int X = thisX + xMoved; int Y = thisY + yMoved; frame.setLocation(X, Y); } }); mainPanel.setLayout(new GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); constraints.insets = new Insets(10, 10, 10, 10); Font font16 = new Font("Arial", Font.BOLD, 16); Font font12 = new Font("Arial", Font.PLAIN, 12); Font font12b = new Font("Arial", Font.BOLD, 12); mainPanel.add(Box.createRigidArea(new Dimension(250, 50))); ImageIcon logo = new ImageIcon(new ImageIcon(XMageLauncher.class.getResource("/label-xmage.png")).getImage() .getScaledInstance(150, 75, Image.SCALE_SMOOTH)); xmageLogo = new JLabel(logo); constraints.gridx = 3; constraints.gridy = 0; constraints.gridheight = 1; constraints.gridwidth = GridBagConstraints.REMAINDER; constraints.anchor = GridBagConstraints.EAST; mainPanel.add(xmageLogo, constraints); textArea = new JTextArea(5, 40); textArea.setEditable(false); textArea.setForeground(Color.WHITE); textArea.setBackground(Color.BLACK); DefaultCaret caret = (DefaultCaret) textArea.getCaret(); caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); scrollPane = new JScrollPane(textArea); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); constraints.gridx = 2; constraints.gridy = 1; constraints.weightx = 1.0; constraints.weighty = 1.0; constraints.fill = GridBagConstraints.BOTH; mainPanel.add(scrollPane, constraints); labelProgress = new JLabel(messages.getString("progress")); labelProgress.setFont(font12); labelProgress.setForeground(Color.WHITE); constraints.gridy = 2; constraints.weightx = 0.0; constraints.weighty = 0.0; constraints.gridwidth = 1; constraints.anchor = GridBagConstraints.WEST; mainPanel.add(labelProgress, constraints); progressBar = new JProgressBar(0, 100); constraints.gridx = 3; constraints.weightx = 1.0; constraints.gridwidth = GridBagConstraints.REMAINDER; constraints.fill = GridBagConstraints.HORIZONTAL; mainPanel.add(progressBar, constraints); JPanel pnlButtons = new JPanel(); pnlButtons.setLayout(new GridBagLayout()); pnlButtons.setOpaque(false); constraints.gridx = 0; constraints.gridy = 3; constraints.gridheight = GridBagConstraints.REMAINDER; constraints.fill = GridBagConstraints.BOTH; mainPanel.add(pnlButtons, constraints); btnLaunchClient = new JButton(messages.getString("launchClient")); btnLaunchClient.setToolTipText(messages.getString("launchClient.tooltip")); btnLaunchClient.setFont(font16); btnLaunchClient.setForeground(Color.GRAY); btnLaunchClient.setEnabled(false); btnLaunchClient.setPreferredSize(new Dimension(180, 60)); btnLaunchClient.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { handleClient(); } }); constraints.gridx = GridBagConstraints.RELATIVE; constraints.gridy = 0; constraints.gridwidth = 1; constraints.fill = GridBagConstraints.BOTH; pnlButtons.add(btnLaunchClient, constraints); btnLaunchClientServer = new JButton(messages.getString("launchClientServer")); btnLaunchClientServer.setToolTipText(messages.getString("launchClientServer.tooltip")); btnLaunchClientServer.setFont(font12b); btnLaunchClientServer.setEnabled(false); btnLaunchClientServer.setForeground(Color.GRAY); btnLaunchClientServer.setPreferredSize(new Dimension(80, 40)); btnLaunchClientServer.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { handleServer(); handleClient(); } }); constraints.fill = GridBagConstraints.HORIZONTAL; pnlButtons.add(btnLaunchClientServer, constraints); btnLaunchServer = new JButton(messages.getString("launchServer")); btnLaunchServer.setToolTipText(messages.getString("launchServer.tooltip")); btnLaunchServer.setFont(font12b); btnLaunchServer.setEnabled(false); btnLaunchServer.setForeground(Color.GRAY); btnLaunchServer.setPreferredSize(new Dimension(80, 40)); btnLaunchServer.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { handleServer(); } }); pnlButtons.add(btnLaunchServer, constraints); btnUpdate = new JButton(messages.getString("update.xmage")); btnUpdate.setToolTipText(messages.getString("update.xmage.tooltip")); btnUpdate.setFont(font12b); btnUpdate.setForeground(Color.BLACK); btnUpdate.setPreferredSize(new Dimension(80, 40)); btnUpdate.setEnabled(true); btnUpdate.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { handleUpdate(); } }); pnlButtons.add(btnUpdate, constraints); btnCheck = new JButton(messages.getString("check.xmage")); btnCheck.setToolTipText(messages.getString("check.xmage.tooltip")); btnCheck.setFont(font12b); btnCheck.setForeground(Color.BLACK); btnCheck.setPreferredSize(new Dimension(80, 40)); btnCheck.setEnabled(true); btnCheck.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { handleCheckUpdates(); } }); pnlButtons.add(btnCheck, constraints); frame.add(mainPanel); frame.pack(); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation(dim.width / 2 - frame.getSize().width / 2, dim.height / 2 - frame.getSize().height / 2); }
From source file:org.pegadi.client.ApplicationLauncher.java
private void jbInit() { ImageIcon icon = new ImageIcon(getClass().getResource("/images/pegadi.gif")); setIconImage(icon.getImage()); this.getContentPane().setLayout(borderLayout1); jPanel1.setLayout(flowLayout1);//from www . ja v a 2s . c o m listerButton.setEnabled(false); publicationButton.setEnabled(false); tetrisButton.setEnabled(false); // ImageIcon reportBugIcon = new // ImageIcon(getClass().getResource(appStrings.getString("icon_open"))); reportBugAction = new AbstractAction(str.getString("menu_help_report")) { public void actionPerformed(ActionEvent e) { reportBug_actionPerformed(e); } }; prefsMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { prefsMenuItem_actionPerformed(e); } }); listerMenuItem .setAccelerator(javax.swing.KeyStroke.getKeyStroke(76, java.awt.event.KeyEvent.CTRL_MASK, false)); listerMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { listerButton_actionPerformed(e); } }); sourcesMenuItem .setAccelerator(javax.swing.KeyStroke.getKeyStroke(73, java.awt.event.KeyEvent.CTRL_MASK, false)); sourcesMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { sourcesButton_actionPerformed(); } }); tetrisMenuItem .setAccelerator(javax.swing.KeyStroke.getKeyStroke(84, java.awt.event.KeyEvent.CTRL_MASK, false)); tetrisMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { tetrisButton_actionPerformed(e); } }); logoutMenuItem .setAccelerator(javax.swing.KeyStroke.getKeyStroke(87, java.awt.event.KeyEvent.CTRL_MASK, false)); logoutMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { logoutMenuItem_actionPerformed(e); } }); quitMenuItem .setAccelerator(javax.swing.KeyStroke.getKeyStroke(81, java.awt.event.KeyEvent.CTRL_MASK, false)); quitMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { quitMenuItem_actionPerformed(e); } }); this.getContentPane().add(jPanel1, BorderLayout.NORTH); jPanel1.add(listerButton, null); listerButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { listerButton_actionPerformed(e); } }); publicationButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { publicationButton_actionPerformed(e); } }); sourcesButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { sourcesButton_actionPerformed(); } }); tetrisButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { tetrisButton_actionPerformed(e); } }); logoutButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { logoutButton_actionPerformed(e); } }); quitButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { quitButton_actionPerformed(e); } }); jPanel1.add(publicationButton, null); jPanel1.add(sourcesButton, null); jPanel1.add(tetrisButton, null); this.getContentPane().add(jPanel2, BorderLayout.EAST); jPanel2.add(usrlabel, null); jPanel2.add(logoutButton, null); jPanel2.add(quitButton, null); menuBar.add(fileMenu); menuBar.add(editMenu); menuBar.add(helpMenu); editMenu.add(prefsMenuItem); fileMenu.add(listerMenuItem); fileMenu.add(sourcesMenuItem); fileMenu.add(tetrisMenuItem); fileMenu.add(logoutMenuItem); fileMenu.add(quitMenuItem); helpMenu.add(reportBugAction); this.setJMenuBar(menuBar); this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { conditionalExit(); } }); this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); }
From source file:com.biosis.biosislite.vistas.inventario.MantenimientoBien.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed // TODO add your handling code here: // JFileChooser fc = new JFileChooser(); // int respuesta = fc.showOpenDialog(this); // if (respuesta == JFileChooser.APPROVE_OPTION) { // File archivoElegido = fc.getSelectedFile(); // String absolute = archivoElegido.getAbsolutePath(); // fotoField.setText(archivoElegido.ge); ////from ww w. j a v a 2 s . co m //// fotolbl.setIcon(new ImageIcon("C:/Users/Documentos/Desktop/HS/" + fotosField.getText())); // ImageIcon fot = new ImageIcon(absolute); // Icon icono = new ImageIcon(fot.getImage().getScaledInstance(fotoLbl.getWidth(), fotoLbl.getHeight(), Image.SCALE_DEFAULT)); // fotoLbl.setIcon(icono); // // } String foto = FormularioUtil.chooserImagen(this); if (!foto.equals("")) { fotoField.setText(foto); ImageIcon fot = new ImageIcon(foto); Icon icono = new ImageIcon( fot.getImage().getScaledInstance(fotoLbl.getWidth(), fotoLbl.getHeight(), Image.SCALE_DEFAULT)); fotoLbl.setIcon(icono); } }
From source file:App.java
protected ImageIcon scaleBufferedImageWithoutLabel(BufferedImage img) { ImageIcon icon = null; try {//from w w w .j a va 2 s.co m icon = new ImageIcon(img); double width = icon.getIconWidth(); double height = icon.getIconHeight(); double labelWidth = 150; double labelHight = 150; double scaleWidth = width / labelWidth; double scaleHeight = height / labelHight; if (width >= height) { // horizontal image double newWidth = width / scaleWidth; icon = new ImageIcon(icon.getImage().getScaledInstance((int) newWidth, -1, Image.SCALE_SMOOTH)); } else { // vertical image double newHeight = height / scaleHeight; icon = new ImageIcon(icon.getImage().getScaledInstance(-1, (int) newHeight, Image.SCALE_SMOOTH)); } } catch (NullPointerException e) { try { originalImage = (BufferedImage) ImageIO.read(new File("img/error.png")); } catch (IOException e2) { e2.printStackTrace(); } e.printStackTrace(); } return icon; }
From source file:gdt.jgui.entity.webset.JWeblinkEditor.java
private void showIconMenu(MouseEvent e) { try {//from www . j av a 2 s . c o m iconMenu = new JPopupMenu(); JMenuItem loadItem = new JMenuItem("Load"); iconMenu.add(loadItem); loadItem.setHorizontalTextPosition(JMenuItem.RIGHT); loadItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { String favicon$ = "http://www.google.com/s2/favicons?domain=" + addressField.getText(); URL url = new URL(favicon$); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); connection.connect(); InputStream input = connection.getInputStream(); ImageIcon icon = new ImageIcon(ImageIO.read(input)); int type = BufferedImage.TYPE_INT_RGB; BufferedImage out = new BufferedImage(24, 24, type); Color background = JWeblinkEditor.this.getBackground(); Graphics2D g2 = out.createGraphics(); g2.setBackground(background); g2.clearRect(0, 0, 24, 24); Image image = icon.getImage(); g2.drawImage(image, 4, 4, null); g2.dispose(); icon = new ImageIcon(out); iconIcon.setIcon(icon); input.close(); } catch (Exception ee) { Logger.getLogger(getClass().getName()).info(ee.toString()); } } }); JMenuItem setItem = new JMenuItem("Set"); iconMenu.add(setItem); setItem.setHorizontalTextPosition(JMenuItem.RIGHT); setItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("WeblinkEditor:set icon"); JIconSelector is = new JIconSelector(); String isLocator$ = is.getLocator(); if (entihome$ != null) isLocator$ = Locator.append(isLocator$, Entigrator.ENTIHOME, entihome$); if (entityKey$ != null) isLocator$ = Locator.append(isLocator$, EntityHandler.ENTITY_KEY, entityKey$); String responseLocator$ = getLocator(); responseLocator$ = Locator.append(responseLocator$, JRequester.REQUESTER_ACTION, ACTION_SET_ICON); responseLocator$ = Locator.append(responseLocator$, BaseHandler.HANDLER_METHOD, "response"); isLocator$ = Locator.append(isLocator$, JRequester.REQUESTER_RESPONSE_LOCATOR, Locator.compressText(responseLocator$)); JConsoleHandler.execute(console, isLocator$); } }); iconMenu.show(e.getComponent(), e.getX(), e.getY()); } catch (Exception ee) { Logger.getLogger(getClass().getName()).severe(ee.toString()); } }
From source file:GUI.GraphicalInterface.java
/** * Constructor to initialize GUI components and data members to default * value.//from w w w.j a va 2 s . co m */ public GraphicalInterface() { initComponents(); Platform.init(); /* Set variables to null */ m_command = m_history = m_completeCommand = ""; m_internalPrefix = m_isManualExecution = false; m_defaultDescription = "Welcome to Grafcom!\n" + "Select a command from the list to view its description. \n" + "Descriptions help you learn how commands work, what arguments they require\n" + "and what values they return.\n" + "================"; m_defaultTerminal = ">> Welcome to Grafcom!\n" + ">> This is the terminal text area which displays the output \n" + "of all the commands you run along with error messages.\n" + ">> Select command from drop-down list or enter manually, \n" + "click Execute and see the output!\n" + "====================\n"; terminalJTextArea.setText(m_defaultTerminal); descriptionJTextArea.setText(m_defaultDescription); m_runtime = Runtime.getRuntime(); m_description = new Description(); bg = new ButtonGroup(); bg.add(listJRadioButton); bg.add(manualJRadioButton); setFont(); /* set icon in title bar */ ImageIcon icon = new ImageIcon("Resources/icon/utilities-terminal.png"); this.setIconImage(icon.getImage()); /* Set default execution path and update GUI */ m_workingDir = new File(System.getProperty("user.dir")); workdirJFileChooser.setCurrentDirectory(m_workingDir); terminalJTextArea.append("\n" + m_workingDir.getPath() + "> "); /* if windows then disable root access */ rootJCheckBox.setEnabled(OS.isFamilyUnix()); commandJTextField.setEnabled(false); executeManualJButton.setEnabled(false); /* set command list */ commandJComboBox.setModel(new javax.swing.DefaultComboBoxModel(Platform.getCommandList().toArray())); }