Example usage for javax.swing JLabel JLabel

List of usage examples for javax.swing JLabel JLabel

Introduction

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

Prototype

public JLabel(Icon image) 

Source Link

Document

Creates a JLabel instance with the specified image.

Usage

From source file:MoveViewSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("JViewport Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Icon icon = new ImageIcon("dog.jpg");
    JLabel dogLabel = new JLabel(icon);
    JViewport viewport = new JViewport();
    viewport.setView(dogLabel);//from  www .  j  a  v  a 2  s.  c om

    InputMap inputMap = viewport.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    ActionMap actionMap = viewport.getActionMap();

    // Up key moves view up unit
    Action upKeyAction = new MoveAction(viewport, DECREASE, Y_AXIS, UNIT);
    KeyStroke upKey = KeyStroke.getKeyStroke("UP");
    inputMap.put(upKey, "up");
    actionMap.put("up", upKeyAction);

    // Down key moves view down unit
    Action downKeyAction = new MoveAction(viewport, INCREASE, Y_AXIS, UNIT);
    KeyStroke downKey = KeyStroke.getKeyStroke("DOWN");
    inputMap.put(downKey, "down");
    actionMap.put("down", downKeyAction);

    // Left key moves view left unit
    Action leftKeyAction = new MoveAction(viewport, DECREASE, X_AXIS, UNIT);
    KeyStroke leftKey = KeyStroke.getKeyStroke("LEFT");
    inputMap.put(leftKey, "left");
    actionMap.put("left", leftKeyAction);

    // Right key moves view right unit
    Action rightKeyAction = new MoveAction(viewport, INCREASE, X_AXIS, UNIT);
    KeyStroke rightKey = KeyStroke.getKeyStroke("RIGHT");
    inputMap.put(rightKey, "right");
    actionMap.put("right", rightKeyAction);

    // PgUp key moves view up block
    Action pgUpKeyAction = new MoveAction(viewport, DECREASE, Y_AXIS, BLOCK);
    KeyStroke pgUpKey = KeyStroke.getKeyStroke("PAGE_UP");
    inputMap.put(pgUpKey, "pgUp");
    actionMap.put("pgUp", pgUpKeyAction);

    // PgDn key moves view down block
    Action pgDnKeyAction = new MoveAction(viewport, INCREASE, Y_AXIS, BLOCK);
    KeyStroke pgDnKey = KeyStroke.getKeyStroke("PAGE_DOWN");
    inputMap.put(pgDnKey, "pgDn");
    actionMap.put("pgDn", pgDnKeyAction);

    // Shift-PgUp key moves view left block
    Action shiftPgUpKeyAction = new MoveAction(viewport, DECREASE, X_AXIS, BLOCK);
    KeyStroke shiftPgUpKey = KeyStroke.getKeyStroke("shift PAGE_UP");
    inputMap.put(shiftPgUpKey, "shiftPgUp");
    actionMap.put("shiftPgUp", shiftPgUpKeyAction);

    // Shift-PgDn key moves view right block
    Action shiftPgDnKeyAction = new MoveAction(viewport, INCREASE, X_AXIS, BLOCK);
    KeyStroke shiftPgDnKey = KeyStroke.getKeyStroke("shift PAGE_DOWN");
    inputMap.put(shiftPgDnKey, "shiftPgDn");
    actionMap.put("shiftPgDn", shiftPgDnKeyAction);

    Container contentPane = frame.getContentPane();
    contentPane.add(viewport, BorderLayout.CENTER);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:ua.com.fielden.platform.example.swing.booking.BookingChartPanelExample.java

public static void main(final String[] args) {
    SwingUtilitiesEx.invokeLater(new Runnable() {

        @Override//from  w w  w.j  a  va  2s .c  om
        public void run() {
            for (final LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(laf.getName())) {
                    try {
                        UIManager.setLookAndFeel(laf.getClassName());
                    } catch (final Exception e) {
                        e.printStackTrace();
                    }
                }
            }
            com.jidesoft.utils.Lm.verifyLicense("Fielden Management Services", "Rollingstock Management System",
                    "xBMpKdqs3vWTvP9gxUR4jfXKGNz9uq52");
            LookAndFeelFactory.installJideExtension();
            final JFrame frame = new JFrame("Booking chart demo");
            final JLabel label = new JLabel("None");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLayout(new MigLayout("fill, insets 0", "[grow, fill]", "[grow, fill][]"));
            frame.add(createBookingChartPanel(label), "wrap");
            frame.add(label);
            frame.setPreferredSize(new Dimension(640, 480));
            frame.pack();
            frame.setVisible(true);
        }
    });
}

From source file:Main.java

public static void main(String[] a) {
    final JFrame jf = new JFrame("JIFrameDemo Main Window");

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    screenSize.width -= 42;//from  w  w  w . jav  a  2s .com
    screenSize.height -= 42;
    jf.setSize(screenSize);
    jf.setLocation(20, 20);

    JMenuBar mb = new JMenuBar();
    jf.setJMenuBar(mb);
    JMenu fm = new JMenu("File");
    mb.add(fm);
    JMenuItem mi;
    fm.add(mi = new JMenuItem("Exit"));
    mi.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });

    JDesktopPane dtp = new JDesktopPane();
    //dtp.setBackground(Color.GREEN);
    jf.setContentPane(dtp);

    JInternalFrame mboxFrame = new JInternalFrame("Mail Reader", true, true, true, true);
    JLabel reader = new JLabel("Mail Reader Would Be Here");
    mboxFrame.setContentPane(reader);
    mboxFrame.setSize(400, 300);
    mboxFrame.setLocation(50, 50);
    mboxFrame.setVisible(true);
    dtp.add(mboxFrame);

    JInternalFrame compFrame = new JInternalFrame("Compose Mail", true, true, true, true);
    JLabel composer = new JLabel("Mail Compose Would Be Here");
    compFrame.setContentPane(composer);
    compFrame.setSize(300, 200);
    compFrame.setLocation(200, 200);
    compFrame.setVisible(true);
    dtp.add(compFrame);

    JInternalFrame listFrame = new JInternalFrame("Users", true, true, true, true);
    JLabel list = new JLabel("List of Users Would Be Here");
    listFrame.setContentPane(list);
    listFrame.setLocation(400, 400);
    listFrame.setSize(500, 200);
    listFrame.setVisible(true);
    dtp.add(listFrame);

    jf.setVisible(true);
    jf.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            jf.setVisible(false);
            jf.dispose();
            System.exit(0);
        }
    });
}

From source file:CustomScrollPane.java

public static void main(String[] args) {
    JFrame f = new JFrame("JScrollBar Demo");
    f.setSize(300, 250);//from   ww  w .j a  v a  2 s  . co  m

    ImageIcon icon = new ImageIcon("earth.jpg");
    CustomScrollPane myScrollPane = new CustomScrollPane(new JLabel(icon));
    f.getContentPane().add(myScrollPane);

    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    f.addWindowListener(wndCloser);
    f.setVisible(true);

}

From source file:ProgressMeterStrmDemo.java

public static void main(String[] av) {
    ProgressMeterStrmDemo demo = new ProgressMeterStrmDemo();
    demo.setSize(100, 100);/*from   w w  w  .j  a va  2 s.  co m*/
    demo.getContentPane().add(new JLabel("ProgressMeterStrmDemo"));
    demo.pack();
    demo.setVisible(true);

}

From source file:ImageSelection.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Drag Image");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Icon icon = new ImageIcon("yourFile.gif");
    JLabel label = new JLabel(icon);
    label.setTransferHandler(new ImageSelection());
    MouseListener listener = new MouseAdapter() {
        public void mousePressed(MouseEvent me) {
            JComponent comp = (JComponent) me.getSource();
            TransferHandler handler = comp.getTransferHandler();
            handler.exportAsDrag(comp, me, TransferHandler.COPY);
        }//from  w  w  w  . j  a  v  a2  s  .  c om
    };
    label.addMouseListener(listener);
    frame.add(new JScrollPane(label), BorderLayout.CENTER);

    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:GrayModel.java

public static void main(String[] args) {
    JFrame frame = new JFrame("SpinnerDemo4");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JComponent newContentPane = new Main();
    newContentPane.setOpaque(true);/*from w ww.j  av  a2 s.  c  o m*/
    frame.setContentPane(newContentPane);

    frame.add(new JLabel("Shade of Gray:"), "North");
    frame.add(new JSpinner(new GrayModel(170)));

    frame.pack();
    frame.setVisible(true);
}

From source file:GrayModel.java

public static void main(String[] args) {
    JFrame frame = new JFrame("SpinnerDemo4");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JComponent newContentPane = new SpinnerDemo4();
    newContentPane.setOpaque(true);//from   w  w w .java  2  s  .  c om
    frame.setContentPane(newContentPane);

    frame.add(new JLabel("Shade of Gray:"), "North");
    frame.add(new JSpinner(new GrayModel(170)));

    frame.pack();
    frame.setVisible(true);
}

From source file:NumericTextField.java

public static void main(String[] args) {
    try {/* w ww .  j  a  v a2  s.c  o  m*/
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception evt) {
    }

    DecimalFormat format = new DecimalFormat("#,###.###");
    format.setGroupingUsed(true);
    format.setGroupingSize(3);
    format.setParseIntegerOnly(false);

    JFrame f = new JFrame("Numeric Text Field Example");
    final NumericTextField tf = new NumericTextField(10, format);

    tf.setValue((double) 123456.789);

    JLabel lbl = new JLabel("Type a number: ");
    f.getContentPane().add(tf, "East");
    f.getContentPane().add(lbl, "West");

    tf.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            try {
                tf.normalize();
                Long l = tf.getLongValue();
                System.out.println("Value is (Long)" + l);
            } catch (ParseException e1) {
                try {
                    Double d = tf.getDoubleValue();
                    System.out.println("Value is (Double)" + d);
                } catch (ParseException e2) {
                    System.out.println(e2);
                }
            }
        }
    });
    f.pack();
    f.setVisible(true);
}

From source file:com.novadart.silencedetect.SilenceDetect.java

public static void main(String[] args) {

    // create the parser
    CommandLineParser parser = new BasicParser();
    try {/*from  w w w.ja  v  a  2s.c  om*/
        // parse the command line arguments
        CommandLine line = parser.parse(OPTIONS, args);

        if (line.hasOption("h")) {

            printHelp();

        } else {

            String decibels = "-10";
            if (line.hasOption("b")) {
                decibels = "-" + line.getOptionValue("b");
            } else {
                throw new RuntimeException();
            }

            String videoFile = null;

            if (line.hasOption("i")) {

                videoFile = line.getOptionValue("i");

                Boolean debug = line.hasOption("d");

                if (line.hasOption("t")) {

                    System.out.println(printAudioTracksList(videoFile, debug));

                } else if (line.hasOption("s")) {

                    int trackNumber = Integer.parseInt(line.getOptionValue("s"));
                    System.out.println(printAudioTrackSilenceDuration(videoFile, trackNumber, decibels, debug));

                } else {

                    printHelp();

                }

            } else if (line.hasOption("-j")) {

                // choose file
                final JFileChooser fc = new JFileChooser();
                fc.setVisible(true);
                int returnVal = fc.showOpenDialog(null);
                if (returnVal == JFileChooser.APPROVE_OPTION) {

                    videoFile = fc.getSelectedFile().getAbsolutePath();

                } else {
                    return;
                }

                JTextArea tracks = new JTextArea();
                tracks.setText(printAudioTracksList(videoFile, true));
                JSpinner trackNumber = new JSpinner();
                trackNumber.setValue(1);
                final JComponent[] inputs = new JComponent[] { new JLabel("Audio Tracks"), tracks,
                        new JLabel("Track to analyze"), trackNumber };
                JOptionPane.showMessageDialog(null, inputs, "Select Audio Track", JOptionPane.PLAIN_MESSAGE);

                JTextArea results = new JTextArea();
                results.setText(printAudioTrackSilenceDuration(videoFile, (int) trackNumber.getValue(),
                        decibels, false));
                final JComponent[] resultsInputs = new JComponent[] { new JLabel("Results"), results };
                JOptionPane.showMessageDialog(null, resultsInputs, "RESULTS!", JOptionPane.PLAIN_MESSAGE);

            } else {
                printHelp();
                return;
            }

        }

    } catch (ParseException | IOException | InterruptedException exp) {
        // oops, something went wrong
        System.out.println("There was a problem :(\nReason: " + exp.getMessage());
    }
}