List of usage examples for java.awt Image getScaledInstance
public Image getScaledInstance(int width, int height, int hints)
From source file:no.met.jtimeseries.chart.ChartPlotter.java
/** * Adds the specified weather symbols to the chart. Symbols are excluded if * necessary to fit in the chart. Specify phenomenon to follow value curve. * Plot on top of chart if phenomenon is null. * //from www. ja v a 2 s . c o m * @return */ public void addWeatherSymbol(SymbolPhenomenon symbols, NumberPhenomenon phenomenon) { boolean followPhenomenon = (phenomenon != null); NumberAxis na; if (!followPhenomenon) { na = new NumberAxis(""); na.setVisible(false); weatherSymbolPlot = new XYPlot(); weatherSymbolPlot.setDomainAxis(plot.getDomainAxis(0)); weatherSymbolPlot.setRangeAxis(na); weatherSymbolPlot.setRangeGridlinesVisible(false); weatherSymbolPlot.setOutlineVisible(false); weatherSymbolPlot.setDomainGridlinesVisible(false); } XYImageAnnotation imageannotation; int imageSize = getWeatherSymbolImageSize(); for (SymbolValueItem symbol : symbols) { Image image = Symbols.getSymbolImage(symbol.getValue()); image = image.getScaledInstance(imageSize, imageSize, Image.SCALE_SMOOTH); if (followPhenomenon) { // plot over the phenomenon curve Double val = phenomenon.getValueByTime(symbol.getTimeFrom()); if (val != null) { double padding = 0.08; // space between curve and symbol in // phenomenon units imageannotation = new XYImageAnnotation(symbol.getTimeFrom().getTime(), val.doubleValue() + padding * (plot.getRangeAxis().getUpperBound() - plot.getRangeAxis().getLowerBound()), image, RectangleAnchor.CENTER); plot.addAnnotation(imageannotation); } } else { // plot symbols on top in separate weatherSymbolPlot imageannotation = new XYImageAnnotation(symbol.getTimeFrom().getTime(), 0.5, image); weatherSymbolPlot.addAnnotation(imageannotation); } } }
From source file:com.digitalgeneralists.assurance.ui.components.ComparisonResultPanel.java
private void buildMergePanel(ComparisonResult result) { this.standardPanel.remove(this.mergePanel); GridBagConstraints mergePanelConstraints = new GridBagConstraints(); mergePanelConstraints.anchor = GridBagConstraints.CENTER; mergePanelConstraints.fill = GridBagConstraints.BOTH; mergePanelConstraints.gridx = 1;//from ww w . java 2 s. com mergePanelConstraints.gridy = 0; mergePanelConstraints.weightx = 0.2; mergePanelConstraints.weighty = 1.0; mergePanelConstraints.gridheight = 1; mergePanelConstraints.gridwidth = 1; mergePanelConstraints.insets = new Insets(0, 0, 0, 0); this.mergePanel = new JPanel(); this.mergePanel.setOpaque(false); GridBagLayout mergePanelGridbag = new GridBagLayout(); this.mergePanel.setLayout(mergePanelGridbag); this.standardPanel.add(this.mergePanel, mergePanelConstraints); AssuranceResultResolution resolution = AssuranceResultResolution.UNRESOLVED; if (result != null) { resolution = result.getResolution(); } if (resolution == AssuranceResultResolution.UNRESOLVED) { if (this.editable) { GridBagConstraints mergeTargetToSourceButtonConstraints = new GridBagConstraints(); mergeTargetToSourceButtonConstraints.anchor = GridBagConstraints.CENTER; mergeTargetToSourceButtonConstraints.gridx = 0; mergeTargetToSourceButtonConstraints.gridy = 0; mergeTargetToSourceButtonConstraints.weightx = 1.0; mergeTargetToSourceButtonConstraints.weighty = 1.0; mergeTargetToSourceButtonConstraints.gridheight = 1; mergeTargetToSourceButtonConstraints.gridwidth = 1; mergeTargetToSourceButtonConstraints.insets = new Insets(5, 5, 5, 5); this.mergeTargetToSourceButton.addActionListener(this); Image icon; try { icon = ImageIO.read(Application.class.getClassLoader().getResource("replace-source.png")); icon = icon.getScaledInstance(25, 25, Image.SCALE_SMOOTH); this.mergeTargetToSourceButton.setIcon(new ImageIcon(icon)); this.mergeTargetToSourceButton.setText(""); this.mergeTargetToSourceButton.setToolTipText("Replace source with target."); } catch (IOException e) { logger.warn("Unable to load icon resources.", e); } this.mergeTargetToSourceButton.setActionCommand(AssuranceActions.replaceSourceAction); this.mergePanel.add(this.mergeTargetToSourceButton, mergeTargetToSourceButtonConstraints); GridBagConstraints mergeSourceToTargetButtonConstraints = new GridBagConstraints(); mergeSourceToTargetButtonConstraints.anchor = GridBagConstraints.CENTER; mergeSourceToTargetButtonConstraints.gridx = 0; mergeSourceToTargetButtonConstraints.gridy = 1; mergeSourceToTargetButtonConstraints.weightx = 1.0; mergeSourceToTargetButtonConstraints.weighty = 1.0; mergeSourceToTargetButtonConstraints.gridheight = 1; mergeSourceToTargetButtonConstraints.gridwidth = 1; mergeSourceToTargetButtonConstraints.insets = new Insets(5, 5, 5, 5); this.mergeSourceToTargetButton.addActionListener(this); try { icon = ImageIO.read(Application.class.getClassLoader().getResource("replace-target.png")); icon = icon.getScaledInstance(25, 25, Image.SCALE_SMOOTH); this.mergeSourceToTargetButton.setIcon(new ImageIcon(icon)); this.mergeSourceToTargetButton.setText(""); this.mergeSourceToTargetButton.setToolTipText("Replace target with source."); } catch (IOException e) { logger.warn("Unable to load icon resources.", e); } this.mergeSourceToTargetButton.setActionCommand(AssuranceActions.replaceTargetAction); this.mergePanel.add(this.mergeSourceToTargetButton, mergeSourceToTargetButtonConstraints); } } else { Image resolutionLabelValue = null; try { switch (result.getResolution()) { case REPLACE_SOURCE: case DELETE_SOURCE: resolutionLabelValue = ImageIO .read(Application.class.getClassLoader().getResource("replace-source.png")); resolutionLabelValue = resolutionLabelValue.getScaledInstance(25, 25, Image.SCALE_SMOOTH); break; case REPLACE_TARGET: case DELETE_TARGET: resolutionLabelValue = ImageIO .read(Application.class.getClassLoader().getResource("replace-target.png")); resolutionLabelValue = resolutionLabelValue.getScaledInstance(25, 25, Image.SCALE_SMOOTH); break; case PROCESSING_ERROR_ENCOUNTERED: resolutionLabelValue = ImageIO .read(Application.class.getClassLoader().getResource("resolution-error.png")); resolutionLabelValue = resolutionLabelValue.getScaledInstance(25, 25, Image.SCALE_SMOOTH); break; default: resolutionLabelValue = ImageIO .read(Application.class.getClassLoader().getResource("undetermined.png")); resolutionLabelValue = resolutionLabelValue.getScaledInstance(25, 25, Image.SCALE_SMOOTH); break; } } catch (IOException e) { logger.warn("Unable to load icon resources.", e); } GridBagConstraints mergeResolutionLabelConstraints = new GridBagConstraints(); mergeResolutionLabelConstraints.anchor = GridBagConstraints.CENTER; mergeResolutionLabelConstraints.gridx = 0; mergeResolutionLabelConstraints.gridy = 0; mergeResolutionLabelConstraints.weightx = 1.0; mergeResolutionLabelConstraints.weighty = 1.0; mergeResolutionLabelConstraints.gridheight = 1; mergeResolutionLabelConstraints.gridwidth = 1; mergeResolutionLabelConstraints.insets = new Insets(5, 5, 5, 5); JLabel mergeResolutionLabel = new JLabel(new ImageIcon(resolutionLabelValue)); this.mergePanel.add(mergeResolutionLabel, mergeResolutionLabelConstraints); if ((result.getResolution() == AssuranceResultResolution.DELETE_SOURCE) || (result.getResolution() == AssuranceResultResolution.DELETE_TARGET)) { File deletedFile = null; if (result.getResolution() == AssuranceResultResolution.DELETE_SOURCE) { deletedFile = result .getSourceDeletedItemLocation(MergeEngine.getApplicationDeletedItemsLocation()); } if (result.getResolution() == AssuranceResultResolution.DELETE_TARGET) { deletedFile = result .getTargetDeletedItemLocation(MergeEngine.getApplicationDeletedItemsLocation()); } if (deletedFile.exists()) { GridBagConstraints mergeRestoreButtonConstraints = new GridBagConstraints(); mergeRestoreButtonConstraints.anchor = GridBagConstraints.CENTER; mergeRestoreButtonConstraints.gridx = 0; mergeRestoreButtonConstraints.gridy = 1; mergeRestoreButtonConstraints.weightx = 1.0; mergeRestoreButtonConstraints.weighty = 1.0; mergeRestoreButtonConstraints.gridheight = 1; mergeRestoreButtonConstraints.gridwidth = 1; mergeRestoreButtonConstraints.insets = new Insets(5, 5, 5, 5); Image icon = null; try { icon = ImageIO.read(Application.class.getClassLoader().getResource("restore.png")); icon = icon.getScaledInstance(25, 25, Image.SCALE_SMOOTH); } catch (IOException e) { logger.warn("Unable to load icon resources.", e); } this.mergeRestoreButton.setIcon(new ImageIcon(icon)); this.mergeRestoreButton.setText(""); this.mergeRestoreButton.setToolTipText("Restore"); this.mergeRestoreButton.addActionListener(this); this.mergeRestoreButton.setActionCommand(AssuranceActions.restoreDeletedItemAction); this.mergePanel.add(this.mergeRestoreButton, mergeRestoreButtonConstraints); } deletedFile = null; } else if (result.getResolution() == AssuranceResultResolution.PROCESSING_ERROR_ENCOUNTERED) { mergeResolutionLabel.setToolTipText(result.getResolutionError()); } } }
From source file:Forms.frm_Penghuni.java
private void btnCariKTPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCariKTPActionPerformed // TODO add your handling code here: FileNameExtensionFilter filter = new FileNameExtensionFilter("Image Files", "jpg", "png", "jpeg"); jfc = new JFileChooser(); jfc.setFileFilter(filter);//w ww . j a va2 s. co m if (jfc.showOpenDialog(pnlKTP) == JFileChooser.APPROVE_OPTION) { Rectangle rect1 = pnlKTP.getBounds(); Toolkit toolkit = Toolkit.getDefaultToolkit(); Image image = toolkit.getImage(jfc.getSelectedFile().getAbsolutePath()); Image imagedResized = image.getScaledInstance(rect1.width, rect1.height, Image.SCALE_DEFAULT); ImageIcon imageIcon = new ImageIcon(imagedResized); pnlKTP.setBackgroundImage(imageIcon); tfPasKTP.setText(jfc.getSelectedFile().getName()); file = new File(jfc.getSelectedFile().getPath()); } }
From source file:Forms.frm_Penghuni.java
private void btnCariFotoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCariFotoActionPerformed // TODO add your handling code here: FileNameExtensionFilter filter = new FileNameExtensionFilter("Image Files", "jpg", "png", "jpeg"); jfc1 = new JFileChooser(); jfc1.setFileFilter(filter);//from ww w. j a v a2 s. co m if (jfc1.showOpenDialog(pnlFoto) == JFileChooser.APPROVE_OPTION) { Rectangle rect = pnlFoto.getBounds(); Toolkit toolkit = Toolkit.getDefaultToolkit(); Image image1 = toolkit.getImage(jfc1.getSelectedFile().getAbsolutePath()); Image imagedResized = image1.getScaledInstance(rect.width, rect.height, Image.SCALE_DEFAULT); ImageIcon imageIcon1 = new ImageIcon(imagedResized); pnlFoto.setBackgroundImage(imageIcon1); tfPasFoto.setText(jfc1.getSelectedFile().getName()); file1 = new File(jfc1.getSelectedFile().getPath()); } }
From source file:processing.app.Theme.java
/** * Return an Image object from inside the Processing lib folder. *///w w w . j a va 2 s. com static public Image getLibImage(String filename, Component who, int width, int height) { Image image = null; // Use vector image when available Resource vectorFile = getThemeResource(filename + ".svg"); if (vectorFile.exists()) { try { image = imageFromSVG(vectorFile.getUrl(), width, height); } catch (Exception e) { System.err.println("Failed to load " + vectorFile + ": " + e.getMessage()); } } Resource bitmapFile = getThemeResource(filename + ".png"); // Otherwise fall-back to PNG bitmaps, allowing user-defined bitmaps to // override built-in svgs if (image == null || bitmapFile.getPriority() > vectorFile.getPriority()) { Resource bitmap2xFile = getThemeResource(filename + "@2x.png"); Resource imageFile; if (((getScale() > 125 && bitmap2xFile.exists()) || !bitmapFile.exists()) && (bitmapFile.isUserDefined() && bitmap2xFile.isUserDefined())) { imageFile = bitmap2xFile; } else { imageFile = bitmapFile; } Toolkit tk = Toolkit.getDefaultToolkit(); image = tk.getImage(imageFile.getUrl()); } MediaTracker tracker = new MediaTracker(who); try { tracker.addImage(image, 0); tracker.waitForAll(); } catch (InterruptedException e) { } if (image.getWidth(null) != width || image.getHeight(null) != height) { image = image.getScaledInstance(width, height, Image.SCALE_SMOOTH); try { tracker.addImage(image, 1); tracker.waitForAll(); } catch (InterruptedException e) { } } return image; }
From source file:Forms.frm_Penghuni.java
private void btnEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditActionPerformed // TODO add your handling code here: if ((tblPenghuni.getSelectedRow() == -1)) { JOptionPane.showMessageDialog(null, "Silahkan pilih baris yang ingin diedit pada Tabel.."); } else {/* w w w . j ava 2s . co m*/ int baris = tblPenghuni.getSelectedRow(); id_penyewa = tblPenghuni.getValueAt(baris, 0).toString(); try { String sql = "Select *from penyewa where id_penyewa = " + id_penyewa + ";"; stt = con.createStatement(); rss = stt.executeQuery(sql); while (rss.next()) { Object[] o = new Object[14]; o[0] = rss.getString("id_penyewa"); o[1] = rss.getString("nama"); o[2] = rss.getString("alamat"); o[3] = rss.getString("tempat_lahir"); o[4] = rss.getDate("tgl_lahir"); o[5] = rss.getString("jk"); o[6] = rss.getString("noktp"); o[7] = rss.getString("nohp"); o[8] = rss.getString("email"); o[9] = rss.getString("pekerjaan"); o[10] = rss.getString("alamat_kerja"); o[11] = rss.getString("notelp_kerja"); o[12] = rss.getString("foto_wajah"); o[13] = rss.getString("foto_ktp"); id_penyewa = rss.getString("id_penyewa"); tfNamaPenghuni.setText(o[1].toString()); tfAlamatPenghuni.setText(o[2].toString()); tfTempatLahirPenghuni.setText(o[3].toString()); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dcTanggalLahirPenghuni.setDate(dateFormat.parse(o[4].toString())); cbGender.setSelectedItem(o[5]); tfEmail.setText(o[8].toString()); tfNomorKTP.setText(o[6].toString()); tfNomorTelp.setText(o[7].toString()); tfPekerjaan.setText(o[9].toString()); tfAlamatPekerjaan.setText(o[10].toString()); tfNomorTelpPekerjaan.setText(o[11].toString()); tfPasFoto.setText(o[12].toString()); tfPasKTP.setText(o[13].toString()); String fotowajah = o[12].toString(); String fotoktp = o[13].toString(); //================== tambah foto ================== try { Toolkit toolkit = Toolkit.getDefaultToolkit(); String path = new File(".").getCanonicalPath(); Rectangle rect2 = pnlFoto.getBounds(); Image image = toolkit.getImage(path + "/image/" + fotowajah); Image imagedResized = image.getScaledInstance(rect2.width, rect2.height, Image.SCALE_DEFAULT); ImageIcon icon = new ImageIcon(imagedResized); pnlFoto.setBackgroundImage(icon); Rectangle rect3 = pnlKTP.getBounds(); Image image1 = toolkit.getImage(path + "/image/" + fotoktp); Image imagedResized1 = image1.getScaledInstance(rect3.width, rect3.height, Image.SCALE_DEFAULT); ImageIcon icon1 = new ImageIcon(imagedResized1); pnlKTP.setBackgroundImage(icon1); } catch (IOException ex) { Logger.getLogger(frm_detail_penghuni.class.getName()).log(Level.SEVERE, null, ex); } //================================================= KunciField(true); } } catch (SQLException e) { System.out.println(e.getMessage()); } catch (ParseException ex) { Logger.getLogger(frm_Penghuni.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:Forms.frm_Penghuni.java
private void btnDetailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDetailActionPerformed // TODO add your handling code here: if (tblPenghuni.getSelectedRowCount() == 1) { int baris = tblPenghuni.getSelectedRow(); String id_penyewa = tblPenghuni.getValueAt(baris, 0).toString(); try {//from w w w . j av a2 s . c om String sql = "Select *from penyewa where id_penyewa = " + id_penyewa + ";"; stt = con.createStatement(); rss = stt.executeQuery(sql); while (rss.next()) { Object[] o = new Object[15]; o[0] = rss.getString("id_penyewa"); o[1] = rss.getString("nama"); o[2] = rss.getString("alamat"); o[3] = rss.getString("tempat_lahir"); o[4] = rss.getDate("tgl_lahir"); o[5] = rss.getString("jk"); o[6] = rss.getString("email"); o[7] = rss.getString("noktp"); o[8] = rss.getString("nohp"); o[9] = rss.getString("pekerjaan"); o[10] = rss.getString("alamat_kerja"); o[11] = rss.getString("notelp_kerja"); o[12] = rss.getString("foto_wajah"); o[13] = rss.getString("foto_ktp"); o[14] = rss.getString("tgl_terdaftar"); frm_detail_penghuni detail = new frm_detail_penghuni(); String nama = o[1].toString(); String alamat = o[2].toString(); String tmptLahir = o[3].toString(); String tglLahir = o[4].toString(); String Gender = o[5].toString(); String email = o[6].toString(); String noKTP = o[7].toString(); String noTelp = o[8].toString(); String pekerjaan = o[9].toString(); String almtPekerjaan = o[10].toString(); String telpPek = o[11].toString(); // String tglMasuk = o[12].toString(); String fotowajah = o[12].toString(); String fotoktp = o[13].toString(); String tgl_daftar = o[14].toString(); // frm_detail_penghuni.pnlDetPasFoto.setText(this.o[1].toString()); // frm_detail_penghuni.pnlDetPasKTP.setText(this.o[1].toString()); frm_detail_penghuni.tfDetNama.setText(nama); frm_detail_penghuni.tfDetAlamat.setText(alamat); frm_detail_penghuni.tfDetTmptLahir.setText(tmptLahir); frm_detail_penghuni.tfDetTglLahir.setText(tglLahir); frm_detail_penghuni.tfDetGender.setText(Gender); frm_detail_penghuni.tfDetEmail.setText(email); frm_detail_penghuni.tfDetNomorKTP.setText(noKTP); frm_detail_penghuni.tfDetNomorTelp.setText(noTelp); frm_detail_penghuni.tfDetPekerjaan.setText(pekerjaan); frm_detail_penghuni.tfDetAlamatPekerjaan.setText(almtPekerjaan); frm_detail_penghuni.tfDetTelpPekerjaan.setText(telpPek); frm_detail_penghuni.tfDetTglMasuk.setText(tgl_daftar); try { Toolkit toolkit = Toolkit.getDefaultToolkit(); String path = new File(".").getCanonicalPath(); Rectangle rect2 = frm_detail_penghuni.pnlDetPasFoto.getBounds(); Image image = toolkit.getImage(path + "/image/" + fotowajah); Image imagedResized = image.getScaledInstance(rect2.width, rect2.height, Image.SCALE_DEFAULT); ImageIcon icon = new ImageIcon(imagedResized); frm_detail_penghuni.pnlDetPasFoto.setBackgroundImage(icon); Rectangle rect3 = frm_detail_penghuni.pnlDetPasKTP.getBounds(); Image image1 = toolkit.getImage(path + "/image/" + fotoktp); Image imagedResized1 = image1.getScaledInstance(rect3.width, rect3.height, Image.SCALE_DEFAULT); ImageIcon icon1 = new ImageIcon(imagedResized1); frm_detail_penghuni.pnlDetPasKTP.setBackgroundImage(icon1); } catch (IOException ex) { Logger.getLogger(frm_detail_penghuni.class.getName()).log(Level.SEVERE, null, ex); } detail.setVisible(true); } } catch (SQLException e) { System.out.println(e.getMessage()); } } else { JOptionPane.showMessageDialog(null, "Silahkan Pilih Pengguna Terlebih Dahulu!.."); } }
From source file:org.sbs.util.ImageCompress.java
/** * @param originalFile/*w ww . j a va 2s .c om*/ * ? * @param resizedFile * ?? * @param width * ? * @param height * ? -1? * @param format * ? jpg, png, gif(?) * @throws IOException */ public void resize(File originalFile, File resizedFile, int width, int height, String format) throws IOException { if (format != null && "gif".equals(format.toLowerCase())) { resize(originalFile, resizedFile, width, height, 1); return; } FileInputStream fis = new FileInputStream(originalFile); ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); int readLength = -1; int bufferSize = 1024; byte bytes[] = new byte[bufferSize]; while ((readLength = fis.read(bytes, 0, bufferSize)) != -1) { byteStream.write(bytes, 0, readLength); } byte[] in = byteStream.toByteArray(); fis.close(); byteStream.close(); Image inputImage = Toolkit.getDefaultToolkit().createImage(in); waitForImage(inputImage); int imageWidth = inputImage.getWidth(null); if (imageWidth < 1) throw new IllegalArgumentException("image width " + imageWidth + " is out of range"); int imageHeight = inputImage.getHeight(null); if (imageHeight < 1) throw new IllegalArgumentException("image height " + imageHeight + " is out of range"); // Create output image. if (height == -1) { double scaleW = (double) imageWidth / (double) width; double scaleY = (double) imageHeight / (double) height; if (scaleW >= 0 && scaleY >= 0) { if (scaleW > scaleY) { height = -1; } else { width = -1; } } } Image outputImage = inputImage.getScaledInstance(width, height, java.awt.Image.SCALE_DEFAULT); checkImage(outputImage); encode(new FileOutputStream(resizedFile), outputImage, format); }
From source file:View.FormPengaturan.java
public void sinkronGambar() { try {// www . j av a 2s. com Profil prof = PengaturanKontrol.getKoneksi().tampilProfil(); String path = new File(".").getCanonicalPath() + "/Gambar/" + prof.getLogo(); Toolkit toolkit = Toolkit.getDefaultToolkit(); Image image = toolkit.getImage(path); Image imagedResized = image.getScaledInstance(110, 100, Image.SCALE_DEFAULT); ImageIcon imageIcon = new ImageIcon(imagedResized); label_kop.setIcon(imageIcon); } catch (IOException ex) { Logger.getLogger(FormPengaturan.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) { Logger.getLogger(FormPengaturan.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:ResourceBundleSupport.java
/** * Attempts to load an image from classpath. If this fails, an empty image * icon is returned./*from w w w . j a v a 2s. c om*/ * * @param resourceName the name of the image. The name should be a global * resource name. * @param scale true, if the image should be scaled, false otherwise * @param large true, if the image should be scaled to 24x24, or * false for 16x16 * @return the image icon. */ private ImageIcon createIcon(final String resourceName, final boolean scale, final boolean large) { final URL in = ObjectUtilities.getResource(resourceName, ResourceBundleSupport.class); ; if (in == null) { System.out.println("Unable to find file in the class path: " + resourceName); return new ImageIcon(createTransparentImage(1, 1)); } final Image img = Toolkit.getDefaultToolkit().createImage(in); if (img == null) { System.out.println("Unable to instantiate the image: " + resourceName); return new ImageIcon(createTransparentImage(1, 1)); } if (scale) { if (large) { return new ImageIcon(img.getScaledInstance(24, 24, Image.SCALE_SMOOTH)); } return new ImageIcon(img.getScaledInstance(16, 16, Image.SCALE_SMOOTH)); } return new ImageIcon(img); }