List of usage examples for javax.swing JLabel JLabel
public JLabel(Icon image)
JLabel
instance with the specified image. From source file:Main.java
public static void main(String args[]) { JFrame f = new JFrame(); f.setSize(new Dimension(300, 300)); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLayout(new FlowLayout()); JLabel label = new JLabel("Update"); String[] data = { "one", "two", "three", "four" }; JList<String> dataList = new JList<>(data); dataList.addListSelectionListener(new ListSelectionListener() { @Override//from w w w . j a v a 2 s .co m public void valueChanged(ListSelectionEvent arg0) { if (!arg0.getValueIsAdjusting()) { label.setText(dataList.getSelectedValue().toString()); } } }); f.add(new JScrollPane(dataList)); f.add(label); f.setVisible(true); }
From source file:MainClass.java
public static void main(final String args[]) { JFrame frame = new JFrame("JSpinner Dates"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); SpinnerModel model3 = new SpinnerNumberModel(); JSpinner spinner3 = new JSpinner(model3); JLabel label3 = new JLabel("Numbers"); JPanel panel3 = new JPanel(new BorderLayout()); panel3.add(label3, BorderLayout.WEST); panel3.add(spinner3, BorderLayout.CENTER); frame.add(panel3, BorderLayout.SOUTH); frame.setSize(200, 90);/* w ww . j ava 2 s .c om*/ frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { File sourceimage = new File("source.gif"); Image image = ImageIO.read(sourceimage); JFrame frame = new JFrame(); JLabel label = new JLabel(new ImageIcon(image)); frame.getContentPane().add(label, BorderLayout.CENTER); frame.pack();/* www . j a v a 2s. com*/ frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JCheckBox a = new JCheckBox("A"); a.setSelected(true);/*from w w w. j a v a 2 s . c o m*/ JCheckBox b = new JCheckBox("B"); JCheckBox c = new JCheckBox("C"); JCheckBox d = new JCheckBox("D"); JFrame frame = new JFrame(); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JLabel("Car Features")); frame.add(a); frame.add(b); frame.add(c); frame.add(d); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame f = new JFrame("JPasswordField Sample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = f.getContentPane(); content.setLayout(new BorderLayout()); Box rowOne = Box.createHorizontalBox(); rowOne.add(new JLabel("Username")); rowOne.add(new JTextField()); Box rowTwo = Box.createHorizontalBox(); rowTwo.add(new JLabel("Password")); rowTwo.add(new JPasswordField()); content.add(rowOne, BorderLayout.NORTH); content.add(rowTwo, BorderLayout.SOUTH); f.setSize(300, 200);// w ww . ja v a 2 s. c om f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Tick Slider"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JSlider jSliderOne = new JSlider(); jSliderOne.setPaintLabels(true);/*from w w w .j av a2 s . c o m*/ Hashtable<Integer, JLabel> table = new Hashtable<Integer, JLabel>(); table.put(0, new JLabel(new ImageIcon("yourFile.gif"))); table.put(10, new JLabel("Ten")); table.put(25, new JLabel("Twenty-Five")); table.put(34, new JLabel("Thirty-Four")); table.put(52, new JLabel("Fifty-Two")); table.put(70, new JLabel("Seventy")); table.put(82, new JLabel("Eighty-Two")); jSliderOne.setLabelTable(table); frame.add(jSliderOne, BorderLayout.NORTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:DefaultFormatterFactoryDemo.java
public static void main(String args[]) { JFrame frame = new JFrame("Mask Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel("Date"); DateFormat displayFormat = new SimpleDateFormat("yyyy--MMMM--dd"); DateFormatter displayFormatter = new DateFormatter(displayFormat); DateFormat editFormat = new SimpleDateFormat("MM/dd/yy"); DateFormatter editFormatter = new DateFormatter(editFormat); DateFormat nullFormat = new SimpleDateFormat("'null'"); DateFormatter nullFormatter = new DateFormatter(nullFormat); DefaultFormatterFactory factory = new DefaultFormatterFactory(displayFormatter, displayFormatter, editFormatter, nullFormatter); JFormattedTextField input = new JFormattedTextField(factory); input.setColumns(30);// w w w. j a va 2 s. c o m JPanel panel = new JPanel(); panel.add(label); panel.add(input); frame.add(panel, "North"); frame.add(new JTextField(), "Center"); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Sample Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border softBevelBorder = new SoftBevelBorder(BevelBorder.RAISED, Color.RED, Color.RED.darker(), Color.PINK, Color.PINK.brighter()); JLabel aLabel = new JLabel("Bevel"); aLabel.setBorder(softBevelBorder);//from w ww . j a v a 2 s . c o m aLabel.setHorizontalAlignment(JLabel.CENTER); frame.add(aLabel); frame.setSize(400, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { InputStream is = new BufferedInputStream(new FileInputStream("s.gif")); Image image = ImageIO.read(is); JFrame frame = new JFrame(); JLabel label = new JLabel(new ImageIcon(image)); frame.getContentPane().add(label, BorderLayout.CENTER); frame.pack();/*from ww w . j av a 2 s.co m*/ frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame aWindow = new JFrame(); aWindow.setBounds(200, 200, 200, 200); aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = aWindow.getContentPane(); content.setLayout(new FlowLayout(FlowLayout.LEFT)); content.add(new JButton("www.java2s.com")); content.add(new JLabel("www.java2s.com")); content.add(new JTextField("www.java2s.com")); aWindow.setVisible(true);/*from w w w.j a v a 2 s. co m*/ }