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:Main.java

public static void main(String[] argv) throws Exception {
    JSlider slider = new JSlider();

    Dictionary table = slider.getLabelTable();

    ImageIcon icon = new ImageIcon("icon.gif");
    JLabel label = new JLabel(icon);

    // Set at desired positions
    table.put(new Integer(slider.getMinimum()), label);
    table.put(new Integer(slider.getMaximum()), label);

    // Force the slider to use the new labels
    slider.setLabelTable(table);//from   w  w  w .j  a va2s  .  com

}

From source file:Main.java

public static void main(final String args[]) {
    JButton button = new JButton("Test");

    button.setHorizontalTextPosition(SwingConstants.LEFT);
    button.setIcon(new ImageIcon("r.gif"));
    button.setRolloverIcon(new ImageIcon("b.gif"));
    button.setRolloverEnabled(true);/*from w  w  w .jav  a2  s .  c o  m*/

    JOptionPane.showMessageDialog(null, button);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame("JLabel Test");

    frame.setSize(300, 200);/*  w  w  w .  j  a  v  a2s. c  o m*/
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    ImageIcon imageIcon = new ImageIcon("icon.gif");
    JLabel label = new JLabel(imageIcon);

    frame.add(label);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JToolBar toolbar = new JToolBar(JToolBar.VERTICAL);

    JButton selectb = new JButton(new ImageIcon("select.gif"));
    JButton freehandb = new JButton(new ImageIcon("freehand.gif"));
    JButton shapeedb = new JButton(new ImageIcon("shapeed.gif"));
    JButton penb = new JButton(new ImageIcon("pen.gif"));

    toolbar.add(selectb);/* ww  w  .  j a v a2s  .com*/
    toolbar.add(freehandb);
    toolbar.add(shapeedb);
    toolbar.add(penb);

    JFrame f = new JFrame();
    f.add(toolbar, BorderLayout.WEST);

    f.setSize(250, 350);
    f.setLocationRelativeTo(null);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTabbedPane pane = new JTabbedPane();
    JButton component = new JButton("button");

    String tooltip = "Tool Tip Text";
    pane.addTab("label", new ImageIcon("icon.png"), component, tooltip);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Icon leafIcon = new ImageIcon("leaf.gif");
    Icon openIcon = new ImageIcon("open.gif");
    Icon closedIcon = new ImageIcon("closed.gif");

    JTree tree = new JTree();
    DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer();
    renderer.setLeafIcon(leafIcon);/*from w  w  w . j  a v  a 2s  .  c  om*/
    renderer.setClosedIcon(closedIcon);
    renderer.setOpenIcon(openIcon);

    JFrame f = new JFrame();
    f.add(new JScrollPane(tree));
    f.setSize(300, 300);
    f.setVisible(true);

}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame("SplitPaneFrame");

    JLabel leftImage = new JLabel(new ImageIcon("a.gif"));
    Component left = new JScrollPane(leftImage);
    JLabel rightImage = new JLabel(new ImageIcon("b.gif"));
    Component right = new JScrollPane(rightImage);

    JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, right);
    split.setDividerLocation(100);//from w ww  .  j  a va2  s  . co m
    frame.getContentPane().add(split);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:InputDialog.java

public static void main(String argv[]) {
    String input = (String) JOptionPane.showInputDialog(new JFrame(),
            "Please enter your favorite Shakespeare play", "Title", JOptionPane.INFORMATION_MESSAGE,
            new ImageIcon("java2sLogo.GIF"), null, "Romeo and Juliet");
    System.out.println("User's input: " + input);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JButton button = new JButton();
    // Icon will appear gray
    button.setEnabled(false);/* ww w  . j ava  2  s .  c  o m*/

    // Set a disabled version of icon
    Icon disabledIcon = new ImageIcon("d.gif");
    button.setDisabledIcon(disabledIcon);

    // To remove the disabled version of the icon, set to null
    button.setDisabledIcon(null);

    button.setDisabledIcon(new ImageIcon("icon.gif"));
}

From source file:PaneInsertionMethods.java

public static void main(String[] args) {

    final JTextPane pane = new JTextPane();

    pane.replaceSelection("text");
    pane.insertIcon(new ImageIcon("imageName.gif"));
    pane.insertComponent(new JButton("Click Me"));

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(pane, BorderLayout.CENTER);
    frame.setSize(360, 180);//  w  w w.j ava 2s.c o  m
    frame.setVisible(true);
}