List of usage examples for javax.swing JLabel JLabel
public JLabel(Icon image)
JLabel
instance with the specified image. From source file:MaskInputSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Mask Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label;/*from w w w . j a v a 2s .co m*/ JFormattedTextField input; JPanel panel; MaskFormatter formatter; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); try { label = new JLabel("SSN"); formatter = new MaskFormatter("###'-##'-####"); input = new JFormattedTextField(formatter); input.setValue("123-45-6789"); input.setColumns(20); panel = new JPanel(); panel.add(label); panel.add(input); frame.add(panel); } catch (ParseException e) { System.err.println("Unable to add SSN"); } frame.pack(); frame.setVisible(true); }
From source file:SpinnerStringsSample.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); 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);//from w ww .ja v a2 s.c o m frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { List<Phone> phones = new ArrayList<>(); phones.add(new Phone("Galaxy", 12345)); phones.add(new Phone("iPhone", 12345)); JPanel panel = new JPanel(new GridLayout(0, 1)); for (Phone phone : phones) { String html = "<html><body style='width:100px'>Phone: " + phone.getName() + "<br/>Model: " + phone.getModel() + "</body></html>"; JLabel label = new JLabel(html); label.setBorder(new MatteBorder(0, 0, 1, 0, Color.BLACK)); panel.add(label);/*from w w w. ja v a 2 s . c o m*/ } JOptionPane.showMessageDialog(null, panel, "Phone List", JOptionPane.PLAIN_MESSAGE); }
From source file:LabelJarSample.java
public static void main(String args[]) { String title = "JLabel Sample"; JFrame frame = new JFrame(title); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = frame.getContentPane(); content.setLayout(new GridLayout(2, 2)); JLabel label1 = new JLabel("Text Label"); content.add(label1);/* w w w .ja v a2 s. c om*/ Image warnImage = ImageLoader.getImage(LabelJarSample.class, "Warn.gif"); Icon warnIcon = new ImageIcon(warnImage); JLabel label2 = new JLabel(warnIcon); content.add(label2); JLabel label3 = new JLabel("Warning", warnIcon, JLabel.CENTER); content.add(label3); String htmlLabel = "<html><sup>HTML</sup> <sub><em>Label</em></sub><br>" + "<font color=\"#FF0080\"><u>Multi-line</u></font>"; JLabel label4 = new JLabel(htmlLabel); content.add(label4); frame.setSize(300, 200); frame.setVisible(true); }
From source file:DnDDemo3.java
public static void main(String[] args) { JPanel north = new JPanel(); north.add(new JLabel("Drag from here:")); JTextField field = new JTextField(10); field.setDragEnabled(true);/* ww w . j a v a2 s. co m*/ north.add(field); final DefaultListModel listModel = new DefaultListModel(); listModel.addElement("first"); listModel.addElement("second"); final JList list = new JList(listModel); list.setDragEnabled(true); list.setTransferHandler(new TransferHandler() { public boolean canImport(TransferHandler.TransferSupport support) { if (!support.isDataFlavorSupported(DataFlavor.stringFlavor)) { return false; } JList.DropLocation dl = (JList.DropLocation) support.getDropLocation(); if (dl.getIndex() == -1) { return false; } else { return true; } } public boolean importData(TransferHandler.TransferSupport support) { if (!canImport(support)) { return false; } Transferable transferable = support.getTransferable(); String data; try { data = (String) transferable.getTransferData(DataFlavor.stringFlavor); } catch (Exception e) { return false; } JList.DropLocation dl = (JList.DropLocation) support.getDropLocation(); int index = dl.getIndex(); if (dl.isInsert()) { listModel.add(index, data); } else { listModel.set(index, data); } Rectangle r = list.getCellBounds(index, index); list.scrollRectToVisible(r); return true; } }); JScrollPane center = new JScrollPane(); center.setViewportView(list); list.setDropMode(DropMode.USE_SELECTION); JPanel cp = new JPanel(); cp.setLayout(new BorderLayout()); cp.add(north, BorderLayout.NORTH); cp.add(center, BorderLayout.CENTER); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(cp); frame.pack(); frame.setVisible(true); }
From source file:MainClass.java
public static void main(final String args[]) { final Object rows[][] = { { "one", "1" }, { "two", "2" }, { "three", "3" } }; final Object headers[] = { "English", "Digit" }; JFrame frame = new JFrame("Scrollless Table"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTable table = new JTable(rows, headers); JScrollPane scrollPane = new JScrollPane(table); JViewport viewport = new JViewport(); viewport.setView(table);/*from w w w . ja v a 2s.c o m*/ scrollPane.setColumnHeaderView(new JLabel("table header here")); scrollPane.setRowHeaderView(viewport); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:JNLPTest.java
public static void main(String args[]) { JFrame frame = new JFrame(); Container content = frame.getContentPane(); JLabel label = new JLabel("Hello, JNLP"); content.add(label, BorderLayout.CENTER); frame.setSize(200, 200);/*w w w . j av a2 s . com*/ frame.show(); try { Thread.sleep(5000); } catch (InterruptedException ignored) { } finally { System.exit(0); } }
From source file:DropModeON.java
public static void main(String[] args) { JPanel north = new JPanel(); north.add(new JLabel("Drag from here:")); JTextField field = new JTextField(10); field.setDragEnabled(true);//ww w. j ava 2 s . c o m north.add(field); final DefaultListModel listModel = new DefaultListModel(); listModel.addElement("first"); listModel.addElement("second"); final JList list = new JList(listModel); list.setDragEnabled(true); list.setTransferHandler(new TransferHandler() { public boolean canImport(TransferHandler.TransferSupport support) { if (!support.isDataFlavorSupported(DataFlavor.stringFlavor)) { return false; } JList.DropLocation dl = (JList.DropLocation) support.getDropLocation(); if (dl.getIndex() == -1) { return false; } else { return true; } } public boolean importData(TransferHandler.TransferSupport support) { if (!canImport(support)) { return false; } Transferable transferable = support.getTransferable(); String data; try { data = (String) transferable.getTransferData(DataFlavor.stringFlavor); } catch (Exception e) { return false; } JList.DropLocation dl = (JList.DropLocation) support.getDropLocation(); int index = dl.getIndex(); if (dl.isInsert()) { listModel.add(index, data); } else { listModel.set(index, data); } // Scroll to display the element that was dropped Rectangle r = list.getCellBounds(index, index); list.scrollRectToVisible(r); return true; } }); JScrollPane center = new JScrollPane(); center.setViewportView(list); list.setDropMode(DropMode.ON); JPanel cp = new JPanel(); cp.setLayout(new BorderLayout()); cp.add(north, BorderLayout.NORTH); cp.add(center, BorderLayout.CENTER); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(cp); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { SwingUtilities.invokeLater(new Runnable() { public void run() { try { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); BufferedImage image = ImageIO.read(new URL("http://www.java2s.com/style/download.png")); f.getContentPane().add(new JLabel(new ImageIcon(dye(image, new Color(255, 0, 0, 128))))); f.pack();// w w w .ja v a 2 s.c o m f.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); }
From source file:DropModeINSERT.java
public static void main(String[] args) { JPanel north = new JPanel(); north.add(new JLabel("Drag from here:")); JTextField field = new JTextField(10); field.setDragEnabled(true);/*from w ww . j a v a 2 s. co m*/ north.add(field); final DefaultListModel listModel = new DefaultListModel(); listModel.addElement("first"); listModel.addElement("second"); final JList list = new JList(listModel); list.setDragEnabled(true); list.setTransferHandler(new TransferHandler() { public boolean canImport(TransferHandler.TransferSupport support) { if (!support.isDataFlavorSupported(DataFlavor.stringFlavor)) { return false; } JList.DropLocation dl = (JList.DropLocation) support.getDropLocation(); if (dl.getIndex() == -1) { return false; } else { return true; } } public boolean importData(TransferHandler.TransferSupport support) { if (!canImport(support)) { return false; } Transferable transferable = support.getTransferable(); String data; try { data = (String) transferable.getTransferData(DataFlavor.stringFlavor); } catch (Exception e) { return false; } JList.DropLocation dl = (JList.DropLocation) support.getDropLocation(); int index = dl.getIndex(); if (dl.isInsert()) { listModel.add(index, data); } else { listModel.set(index, data); } // Scroll to display the element that was dropped Rectangle r = list.getCellBounds(index, index); list.scrollRectToVisible(r); return true; } }); JScrollPane center = new JScrollPane(); center.setViewportView(list); list.setDropMode(DropMode.INSERT); JPanel cp = new JPanel(); cp.setLayout(new BorderLayout()); cp.add(north, BorderLayout.NORTH); cp.add(center, BorderLayout.CENTER); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(cp); frame.pack(); frame.setVisible(true); }