Example usage for javax.swing ImageIcon ImageIcon

List of usage examples for javax.swing ImageIcon ImageIcon

Introduction

In this page you can find the example usage for javax.swing ImageIcon ImageIcon.

Prototype

public ImageIcon(byte[] imageData) 

Source Link

Document

Creates an ImageIcon from an array of bytes which were read from an image file containing a supported image format, such as GIF, JPEG, or (as of 1.3) PNG.

Usage

From source file:ru.codemine.pos.ui.windows.misc.ShopSettingsWindow.java

public ShopSettingsWindow() {
    setTitle("??  ");
    setMinimumSize(new Dimension(800, 400));
    setLocationRelativeTo(null);// w w w  .ja va  2s.c o  m

    actionListenersInit = false;

    saveButton = new WebButton("", new ImageIcon("images/icons/default/16x16/button-ok.png"));
    cancelButton = new WebButton("", new ImageIcon("images/icons/default/16x16/button-cancel.png"));
    saveButton.setMargin(5);
    cancelButton.setMargin(5);
    saveButton.setRound(StyleConstants.largeRound);
    cancelButton.setRound(StyleConstants.largeRound);
    buttonsGroupPanel = new GroupPanel(10, saveButton, cancelButton);

    nameLabel = new WebLabel("? ");
    addressLabel = new WebLabel("??");
    orgLabel = new WebLabel("  (??  )");
    orgNameLabel = new WebLabel("? ");
    orgInnLabel = new WebLabel("??");
    orgKppLabel = new WebLabel("");

    nameField = new WebTextField();
    addressTextArea = new WebTextArea();
    orgNameField = new WebTextField();
    orgInnField = new WebTextField();
    orgKppField = new WebTextField();

    TableLayout layout = new TableLayout(new double[][] {
            { 10, TableLayout.PREFERRED, 10, TableLayout.FILL, 10, TableLayout.PREFERRED, 10, TableLayout.FILL,
                    10 },
            { 10, TableLayout.PREFERRED, // name
                    10, TableLayout.FILL, // address
                    10, TableLayout.PREFERRED, // orglabel
                    10, TableLayout.PREFERRED, // orgname
                    10, TableLayout.PREFERRED, // inn, kpp
                    10, TableLayout.PREFERRED, 10 } // 
    });
    setLayout(layout);

    add(nameLabel, "1, 1");
    add(nameField, "3, 1, 7, 1, F, F");
    add(addressLabel, "1, 3");
    add(new WebScrollPane(addressTextArea), "3, 3, 7, 3, F, F");
    add(orgLabel, "1, 5, 7, 5, C, T");
    add(orgNameLabel, "1, 7");
    add(orgNameField, "3, 7, 7, 7, F, F");
    add(orgInnLabel, "1, 9");
    add(orgInnField, "3, 9");
    add(orgKppField, "5, 9");
    add(orgKppField, "7, 9");
    add(buttonsGroupPanel, "1, 11, 7, 11, C, T");
}

From source file:net.sf.keystore_explorer.gui.actions.GenerateCsrAction.java

/**
 * Construct action.//from   w  ww . j  a v a 2s .c  om
 *
 * @param kseFrame
 *            KeyStore Explorer frame
 */
public GenerateCsrAction(KseFrame kseFrame) {
    super(kseFrame);

    putValue(LONG_DESCRIPTION, res.getString("GenerateCsrAction.statusbar"));
    putValue(NAME, res.getString("GenerateCsrAction.text"));
    putValue(SHORT_DESCRIPTION, res.getString("GenerateCsrAction.tooltip"));
    putValue(SMALL_ICON, new ImageIcon(Toolkit.getDefaultToolkit()
            .createImage(getClass().getResource(res.getString("GenerateCsrAction.image")))));
}

From source file:tarea1.histogram.java

private void display() {
    JFrame f = new JFrame("Histogram");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(createChartPanel());//from  ww w.  j a va 2s  .co m
    f.add(new JLabel(new ImageIcon(image)), BorderLayout.WEST);
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:com.akman.excel.view.frmExportExcel.java

public void getImage() {
    Connection conn = Javaconnect.ConnecrDb();
    PreparedStatement pst = null;
    ResultSet rs = null;/*from   w  w w .j  a  va2s .c o m*/
    try {

        String sql = "SELECT MAX(ID), Image FROM ExcelData";

        pst = conn.prepareStatement(sql);

        rs = pst.executeQuery();

        if (rs.next()) {
            byte[] imagedata = rs.getBytes("Image");
            format = new ImageIcon(imagedata);
            Rectangle rect = lblImage.getBounds();
            //Scaling the image to fit in the picLabel
            Image scaledimage = format.getImage().getScaledInstance(rect.width, rect.height,
                    Image.SCALE_DEFAULT);
            //converting the image back to image icon to make an acceptable picLabel
            format = new ImageIcon(scaledimage);

            lblImage.setIcon(format);
        }

    } catch (SQLException ex) {
        Logger.getLogger(frmSelectImage.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        DbUtils.closeQuietly(rs);
        DbUtils.closeQuietly(pst);
        DbUtils.closeQuietly(conn);
    }
}

From source file:user.CreateChart.java

private ImageIcon barChart(CategoryDataset dataset, String name, String X, String Y) {

    final JFreeChart chart = ChartFactory.createBarChart(name, // chart title
            X, // domain axis label
            Y, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/*from   www .j  ava2s . c o m*/
    final CategoryPlot plot = chart.getCategoryPlot();
    final org.jfree.chart.axis.NumberAxis rangeAxis = (org.jfree.chart.axis.NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(org.jfree.chart.axis.NumberAxis.createIntegerTickUnits());

    ImageIcon ii = new ImageIcon(chart.createBufferedImage(592, 500));
    return ii;
}

From source file:jatoo.resources.ResourcesImages.java

/**
 * Gets the {@link ImageIcon} with the given name. If the icon was not found,
 * the fallback (if it was provided) will be used.
 * /*from  w  ww.  j ava  2 s.com*/
 * @param name
 *          the name of the desired icon
 * 
 * @return the icon with the given name, o <code>null</code> if the icon was
 *         not found
 */
public ImageIcon getImageIcon(final String name) {

    ImageIcon icon;

    try {
        icon = new ImageIcon(clazz.getResource(name));
    }

    catch (Exception e) {

        if (fallback != null) {
            icon = fallback.getImageIcon(name);
        }

        else {
            icon = null;
            logger.error("no image icon #" + name);
        }
    }

    return icon;
}

From source file:com.google.code.facebook.graph.sna.applet.VisualizationImageServerDemo.java

/**
 * //from ww  w . j  a v a 2  s  .  c o  m
 */
public VisualizationImageServerDemo() {

    // create a simple graph for the demo
    graph = new DirectedSparseMultigraph<String, Number>();
    String[] v = createVertices(10);
    createEdges(v);

    vv = new VisualizationImageServer<String, Number>(new KKLayout<String, Number>(graph),
            new Dimension(600, 600));

    vv.getRenderer().setVertexRenderer(new GradientVertexRenderer<String, Number>(Color.white, Color.red,
            Color.white, Color.blue, vv.getPickedVertexState(), false));
    vv.getRenderContext().setEdgeDrawPaintTransformer(new ConstantTransformer(Color.lightGray));
    vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray));
    vv.getRenderContext().setArrowDrawPaintTransformer(new ConstantTransformer(Color.lightGray));

    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
    vv.getRenderer().getVertexLabelRenderer().setPositioner(new InsidePositioner());
    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.AUTO);

    // create a frome to hold the graph
    final JFrame frame = new JFrame();
    Container content = frame.getContentPane();

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Image im = vv.getImage(new Point2D.Double(300, 300), new Dimension(600, 600));
    Icon icon = new ImageIcon(im);
    JLabel label = new JLabel(icon);
    content.add(label);
    frame.pack();
    frame.setVisible(true);
}

From source file:org.pmedv.core.util.ResourceUtils.java

/**
 * Create an ImageIcon from the image at the specified path
 * /*w w w.j  av  a  2 s .c om*/
 * @param path The path of the image
 * 
 * @return The image icon, or null if the image doesn't exist
 */
public static ImageIcon createImageIcon(String path) {

    URL u = Thread.currentThread().getContextClassLoader().getResource(path);

    // TODO : Check if that works with webstart

    // URL u = ClassLoader.getSystemResource(realPath);//UIUtils.class.getResource(path);

    if (u == null)
        return null;
    return new ImageIcon(u);
}

From source file:GUI.Main.java

static private WebPanel createAdminPanel(String url, String firstName, String lastName, final int myId)
        throws IOException {

    mainPanel.setPaintFocus(true);/*from  w  w  w  . j  av a  2  s  . c  o m*/

    // Text field input Search
    textSearchField = new WebTextField(15);
    textSearchField.setInputPrompt("Search");
    textSearchField.setInputPromptFont(textSearchField.getFont().deriveFont(Font.ROMAN_BASELINE));
    textSearchField.setTrailingComponent(new WebImage("resources/search.png"));
    System.out.println("My id" + myId);
    // Boite Message
    WebButton boiteMessageButton = new WebButton("Ouvrir ma Boite Message");
    boiteMessageButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JFrame boiteFrame = new JFrame("Boite de messages");
            boiteFrame.setLocationRelativeTo(null);
            JPanel boite = new JPanel(new BorderLayout());
            boite.add(new BoiteReception(myId), BorderLayout.CENTER);
            boiteFrame.add(boite);
            boiteFrame.setIconImage(new ImageIcon(getClass().getResource("/images/message.png")).getImage());
            boiteFrame.pack();
            boiteFrame.setLocationRelativeTo(boite);
            boiteFrame.setVisible(true);
        }
    });
    // Text Button Search
    WebButton SearchButton = new WebButton("Search");
    SearchButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {

                new ListOfOffres1().openListOfOffresFrameagn(1, textSearchField.getText(), myId);
            } catch (IOException ex) {
                Logger.getLogger(ListOfOffres1.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
    // Exit Button 
    WebButton logOutButton = new WebButton("Exit");
    logOutButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            ListOfOffresFrame.setVisible(false); //you can't see me!
            ListOfOffresFrame.dispose(); //Destroy the JFrame object
            ListOfOffresFrame = null;
            System.exit(0);
        }
    });
    // Text Button Retour
    exitButton = new WebButton("Retour");

    exitButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println("Retour clicked");
            ListOfOffres1.openPleaseWait();
            try {
                System.out.println("aaaaaaaaaaaaaaaaaaaaaaaa" + myId);
                new ListOfOffres1().openListOfOffresFrameagn(0, "", myId);
            } catch (IOException ex) {
                Logger.getLogger(ListOfOffres1.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    });
    final WebPanel descPanel = new WebPanel(false);

    GroupPanel OffrePanel = new GroupPanel(GroupingType.fillFirst, 5, false);

    descPanel.setOpaque(false);
    descPanel.setMargin(50, 50, 50, 50);
    mainPanel.setPaintFocus(true);
    mainPanel.setMargin(10);
    System.out.print(url);
    // load the image once

    mainPanel.setPreferredSize(new Dimension(300, 100));
    OffrePanel.add(new GroupPanel(GroupingType.fillFirst, 5, false, loadImageX(url),
            new WebLabel("<html><body><h1><font color=#555555>" + firstName + " " + lastName
                    + "</font></h1></body></html>", WebLabel.CENTER),
            textSearchField, SearchButton, new WhiteSpace(),
            new GroupPanel(GroupingType.fillFirst, false, new WhiteSpace(), boiteMessageButton,
                    new GroupPanel(GroupingType.fillFirstAndLast, 5, true, exitButton, logOutButton))));
    mainPanel.add(OffrePanel);
    return mainPanel;
}

From source file:com.microsoft.azure.hdinsight.common.StreamUtil.java

public static ImageIcon getImageResourceFile(String resourcePath) {
    URL url = classLoader.getResource(resourcePath);

    if (url != null) {
        return new ImageIcon(url);
    } else {/*from  w  w w. j  ava2s .  c  om*/
        return null;
    }
}