List of usage examples for javax.swing JLabel JLabel
public JLabel(Icon image)
JLabel
instance with the specified image. From source file:WindowsLookAndFeelDemo.java
public static void main(String[] args) { try {/* ww w. j a v a 2 s . c o m*/ UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception e) { e.printStackTrace(); } JLabel label = new JLabel("Label"); JTextField field = new JTextField("www.java2s.com!"); JList list = new JList(new String[] { "A", "B", "C" }); JScrollPane listPane = new JScrollPane(list); listPane.setPreferredSize(new Dimension(250, 100)); JScrollPane treePane = new JScrollPane(new JTree()); treePane.setPreferredSize(new Dimension(250, 100)); JButton button = new JButton("Click me"); JPanel cp = new JPanel(); cp.add(label); cp.add(field); cp.add(listPane); cp.add(treePane); cp.add(button); JFrame frame = new JFrame(); frame.setTitle("Windows Look and Feel Demo"); frame.setPreferredSize(new Dimension(280, 300)); 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[]) { JPanel container = new ScrollablePanel(); container.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0)); for (int i = 0; i < 20; ++i) { JPanel p = new JPanel(); p.setPreferredSize(new Dimension(50, 50)); p.add(new JLabel("" + i)); container.add(p);/*w w w . jav a 2 s. c o m*/ } JScrollPane scroll = new JScrollPane(container); scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(scroll); f.pack(); f.setSize(250, 300); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JCheckBox a = new JCheckBox("A"); a.setSelected(true);//from ww w. ja v a 2 s . c o m a.setMnemonic(KeyEvent.VK_A); 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:MainClass.java
public static void main(String args[]) throws Exception { JFrame frame = new JFrame("Mask Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label;//from ww w. j a v a 2 s.c om JFormattedTextField input; JPanel panel; MaskFormatter formatter; try { label = new JLabel("US Phone"); formatter = new MaskFormatter("'(###')' ###'-####"); formatter.setPlaceholderCharacter('*'); input = new JFormattedTextField(formatter); input.setColumns(20); panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(label); panel.add(input); frame.add(panel); } catch (ParseException e) { System.err.println("Unable to add Phone"); } frame.pack(); frame.setVisible(true); }
From source file:OffsetSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Offset Example"); Container content = frame.getContentPane(); JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name: "); label.setDisplayedMnemonic(KeyEvent.VK_N); final JTextField textField = new JTextField(); label.setLabelFor(textField);//from w ww. j av a 2 s . c om panel.add(label, BorderLayout.WEST); panel.add(textField, BorderLayout.CENTER); content.add(panel, BorderLayout.NORTH); JButton button = new JButton("Get Offset"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println("Offset: " + textField.getScrollOffset()); System.out.println("Visibility: " + textField.getHorizontalVisibility()); BoundedRangeModel model = textField.getHorizontalVisibility(); int extent = model.getExtent(); textField.setScrollOffset(extent); } }; button.addActionListener(actionListener); content.add(button, BorderLayout.SOUTH); frame.setSize(250, 150); frame.setVisible(true); }
From source file:CornerSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Cornering Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Icon miniLogo = new ImageIcon("logo.gif"); Icon acrossLogo = new ImageIcon("logo-across.jpg"); Icon downLogo = new ImageIcon("logo-down.jpg"); Icon bookCover = new ImageIcon("puzzlebook.jpg"); JLabel logoLabel = new JLabel(miniLogo); JLabel columnLabel = new JLabel(acrossLogo); JLabel rowLabel = new JLabel(downLogo); JLabel coverLabel = new JLabel(bookCover); JScrollPane scrollPane = new JScrollPane(coverLabel); scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, logoLabel); scrollPane.setColumnHeaderView(columnLabel); scrollPane.setRowHeaderView(rowLabel); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 200);//from w ww .ja v a 2s.co m frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { int ROWS = 100; JPanel content = new JPanel(); content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS)); content.add(new JLabel("Thanks for helping out. Use tab to move around.")); for (int i = 0; i < ROWS; i++) { JTextField field = new JTextField("" + i); field.setName("field#" + i); content.add(field);/*ww w . ja v a 2 s . c o m*/ } KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener("focusOwner", new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (!(evt.getNewValue() instanceof JComponent)) { return; } JViewport viewport = (JViewport) content.getParent(); JComponent focused = (JComponent) evt.getNewValue(); if (content.isAncestorOf(focused)) { Rectangle rect = focused.getBounds(); Rectangle r2 = viewport.getVisibleRect(); content.scrollRectToVisible( new Rectangle(rect.x, rect.y, (int) r2.getWidth(), (int) r2.getHeight())); } } }); JFrame window = new JFrame(); window.setContentPane(new JScrollPane(content)); window.setSize(200, 200); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) { JFrame frame = new JFrame("Range Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new GridLayout(3, 2)); frame.add(new JLabel("Range: 0-255")); JTextField textFieldOne = new JTextField(); Document textDocOne = textFieldOne.getDocument(); DocumentFilter filterOne = new IntegerRangeDocumentFilter(0, 255); ((AbstractDocument) textDocOne).setDocumentFilter(filterOne); frame.add(textFieldOne);//from w w w . j a v a 2 s . com frame.setSize(250, 150); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { JFrame frame = new JFrame("Cornering Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("+"); JLabel bigLabel = new JLabel("A"); bigLabel.setPreferredSize(new Dimension(400, 400)); bigLabel.setBorder(new LineBorder(Color.red)); JScrollPane scrollPane = new JScrollPane(bigLabel); scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, button); scrollPane.setColumnHeaderView(new JLabel("B")); scrollPane.setRowHeaderView(new JLabel("C")); ActionListener actionListener = new JScrollPaneToTopAction(scrollPane); button.addActionListener(actionListener); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 200);/*from ww w . ja va 2 s . c om*/ frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400, 400);/*from w w w . jav a2 s .com*/ JDialog dialog = new JDialog(frame, "Dialog", true); JPanel mainGui = new JPanel(new BorderLayout()); mainGui.setBorder(new EmptyBorder(20, 20, 20, 20)); mainGui.add(new JLabel("Contents go here"), BorderLayout.CENTER); JPanel buttonPanel = new JPanel(new FlowLayout()); mainGui.add(buttonPanel, BorderLayout.SOUTH); JButton close = new JButton("Close"); close.addActionListener(e -> dialog.setVisible(false)); buttonPanel.add(close); frame.setVisible(true); dialog.setContentPane(mainGui); dialog.pack(); dialog.setVisible(true); }