List of usage examples for javax.swing JLabel JLabel
public JLabel(Icon image)
JLabel
instance with the specified image. From source file:TabComponent.java
public static void main(String[] args) { JTabbedPane pane = new JTabbedPane(); String title = "Tab"; pane.add(title, new JLabel(title)); pane.setTabComponentAt(0, new TabComponent(title, pane)); JFrame frame = new JFrame("Tab Component Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(pane);// w w w . j a v a 2 s. c o m frame.setSize(500, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws IOException { BufferedImage original = ImageIO.read(new URL("http://www.java2s.com/style/download.png")); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); BufferedImage rotated1 = create(original, -Math.PI / 2, gc); BufferedImage rotated2 = create(original, +Math.PI / 4, gc); BufferedImage rotated3 = create(original, Math.PI, gc); JPanel cp = new JPanel(); cp.add(new JLabel(new ImageIcon(original))); cp.add(new JLabel(new ImageIcon(rotated1))); cp.add(new JLabel(new ImageIcon(rotated2))); cp.add(new JLabel(new ImageIcon(rotated3))); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setContentPane(cp);/*from ww w . ja v a 2 s. c o m*/ f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("JSpinner Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DateFormatSymbols symbols = new DateFormatSymbols(Locale.FRENCH); String days[] = symbols.getWeekdays(); SpinnerModel model1 = new SpinnerListModel(days); JSpinner spinner1 = new JSpinner(model1); ChangeListener listener = new ChangeListener() { public void stateChanged(ChangeEvent e) { System.out.println("Source: " + e.getSource()); }//w w w . ja v a 2 s . com }; spinner1.addChangeListener(listener); JLabel label1 = new JLabel("French Days/List"); JPanel panel1 = new JPanel(new BorderLayout()); panel1.add(label1, BorderLayout.WEST); panel1.add(spinner1, BorderLayout.CENTER); frame.add(panel1, BorderLayout.NORTH); frame.setSize(200, 90); frame.setVisible(true); }
From source file:DynamicIconExample.java
public static void main(String[] args) { final JSlider width = new JSlider(JSlider.HORIZONTAL, 1, 150, 75); final JSlider height = new JSlider(JSlider.VERTICAL, 1, 150, 75); class DynamicIcon implements Icon { public int getIconWidth() { return width.getValue(); }//w w w . ja va2 s.c o m public int getIconHeight() { return height.getValue(); } public void paintIcon(Component c, Graphics g, int x, int y) { g.fill3DRect(x, y, getIconWidth(), getIconHeight(), true); } } Icon icon = new DynamicIcon(); final JLabel dynamicLabel = new JLabel(icon); class Updater implements ChangeListener { public void stateChanged(ChangeEvent ev) { dynamicLabel.repaint(); } } Updater updater = new Updater(); width.addChangeListener(updater); height.addChangeListener(updater); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container c = f.getContentPane(); c.setLayout(new BorderLayout()); c.add(width, BorderLayout.NORTH); c.add(height, BorderLayout.WEST); c.add(dynamicLabel, BorderLayout.CENTER); f.setSize(210, 210); f.setVisible(true); }
From source file:MainClass.java
public static void main(String[] args) { JFrame frame = new JFrame(); Calendar now = Calendar.getInstance(); Calendar earliest = (Calendar) now.clone(); earliest.add(Calendar.MONTH, -6); Calendar latest = (Calendar) now.clone(); latest.add(Calendar.MONTH, 6); SpinnerModel model = new SpinnerDateModel(now.getTime(), earliest.getTime(), latest.getTime(), Calendar.WEEK_OF_YEAR); final JSpinner spinner = new JSpinner(model); model.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { System.out.println(((SpinnerDateModel) e.getSource()).getDate()); }/*from w ww .ja va 2s .c o m*/ }); frame.getContentPane().add("North", new JLabel("Choose a week")); frame.getContentPane().add("Center", spinner); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Clip Image"); Container contentPane = frame.getContentPane(); final Clipboard clipboard = frame.getToolkit().getSystemClipboard(); Icon icon = new ImageIcon("jaeger.jpg"); final JLabel label = new JLabel(icon); label.setTransferHandler(new ImageSelection()); JScrollPane pane = new JScrollPane(label); contentPane.add(pane, BorderLayout.CENTER); JButton copy = new JButton("Copy"); copy.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { TransferHandler handler = label.getTransferHandler(); handler.exportToClipboard(label, clipboard, TransferHandler.COPY); }/*from ww w . j a va 2s . c o m*/ }); JButton clear = new JButton("Clear"); clear.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { label.setIcon(null); } }); JButton paste = new JButton("Paste"); paste.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Transferable clipData = clipboard.getContents(clipboard); if (clipData != null) { if (clipData.isDataFlavorSupported(DataFlavor.imageFlavor)) { TransferHandler handler = label.getTransferHandler(); handler.importData(label, clipData); } } } }); JPanel p = new JPanel(); p.add(copy); p.add(clear); p.add(paste); contentPane.add(p, BorderLayout.SOUTH); frame.setSize(300, 300); frame.show(); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Sorting JTable"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); MyTableModel model = new MyTableModel(); JTable table = new JTable(model); final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model); table.setRowSorter(sorter);/*from www. ja va2s . co m*/ JScrollPane pane = new JScrollPane(table); frame.add(pane, BorderLayout.CENTER); JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Filter"); panel.add(label, BorderLayout.WEST); final JTextField filterText = new JTextField("Y"); panel.add(filterText, BorderLayout.CENTER); frame.add(panel, BorderLayout.NORTH); JButton button = new JButton("Filter"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String text = filterText.getText(); try { sorter.setRowFilter(RowFilter.regexFilter(text)); } catch (PatternSyntaxException pse) { System.err.println("Bad regex pattern"); } } }); frame.add(button, BorderLayout.SOUTH); frame.setSize(300, 250); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { Object[] items = new Object[] { "Dog", "Cat", "Other" }; DefaultComboBoxModel dcbm = new DefaultComboBoxModel(items); JComboBox comboBox = new JComboBox(dcbm); comboBox.setPreferredSize(new Dimension(200, 20)); comboBox.addItemListener(e -> {/* w ww.jav a 2s. c om*/ Object selectedItem = comboBox.getSelectedItem(); boolean editable = selectedItem instanceof String && ((String) selectedItem).equals("Other"); comboBox.setEditable(editable); }); comboBox.getEditor().addActionListener(e -> { Object newItem = comboBox.getEditor().getItem(); DefaultComboBoxModel d = (DefaultComboBoxModel) comboBox.getModel(); d.addElement(newItem); d.setSelectedItem(newItem); }); JPanel content = new JPanel(new FlowLayout()); content.add(new JLabel("Test:")); content.add(comboBox); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(content); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { URL urlImage1 = new URL("http://www.java2s.com/style/download.png"); final Image fgImage = ImageIO.read(urlImage1); int w = fgImage.getWidth(null); int h = fgImage.getHeight(null); final BufferedImage bgImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); final BufferedImage finalImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g = finalImage.createGraphics(); g.drawImage(bgImage, 0, 0, null);/*from w ww. jav a2s . c o m*/ g.drawImage(fgImage, 0, 0, null); g.dispose(); Runnable r = new Runnable() { @Override public void run() { JPanel gui = new JPanel(new GridLayout(1, 0, 5, 5)); gui.add(new JLabel(new ImageIcon(bgImage))); gui.add(new JLabel(new ImageIcon(fgImage))); gui.add(new JLabel(new ImageIcon(finalImage))); JOptionPane.showMessageDialog(null, gui); } }; SwingUtilities.invokeLater(r); }
From source file:Main.java
public static void main(String[] args) { final JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton loadButton = new JButton("Display Image"); loadButton.addActionListener(ev -> { JFileChooser fc = new JFileChooser(System.getProperty("user.home")); fc.addChoosableFileFilter(/* w ww . java 2 s. com*/ new FileNameExtensionFilter("Image files", new String[] { "png", "jpg", "jpeg", "gif" })); if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { try { Image image = ImageIO.read(fc.getSelectedFile()); if (image != null) { JPanel panel = new JPanel(new BorderLayout(10, 10)); panel.add(new JLabel(fc.getSelectedFile().toString()), BorderLayout.NORTH); panel.add(new JLabel(new ImageIcon(image))); JOptionPane.showMessageDialog(frame, panel); } } catch (Exception ex) { ex.printStackTrace(); } } }); frame.add(loadButton); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true); }