List of usage examples for javax.swing JLabel JLabel
public JLabel(Icon image)
JLabel
instance with the specified image. From source file:JFramePack.java
public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame(); frame.setTitle("My First Swing Application"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel("Welcome"); frame.add(label);//from w w w. j ava 2 s .c om frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame f = new JFrame("JSeparator Sample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLayout(new GridLayout(0, 1)); JLabel above = new JLabel("Above Separator"); f.add(above);//from w w w . jav a 2s . c o m JSeparator separator = new JSeparator(); f.add(separator); JLabel below = new JLabel("Below Separator"); f.add(below); f.setSize(300, 100); f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name: "); label.setDisplayedMnemonic(KeyEvent.VK_N); JTextField textField = new JTextField(); label.setLabelFor(textField);/* w w w. java2s. c o m*/ panel.add(label, BorderLayout.WEST); panel.add(textField, BorderLayout.CENTER); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(panel, BorderLayout.NORTH); frame.add(new JButton("Somewhere Else"), BorderLayout.SOUTH); frame.setSize(250, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("Test"); JPanel panel = new JPanel(); JLabel label = new JLabel("CenteredJLabel"); panel.setLayout(new GridBagLayout()); panel.add(label);/*w w w .j a v a2 s . com*/ panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.add(panel); frame.setSize(400, 300); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel ui = new JPanel(new BorderLayout(1, 1)); JTabbedPane jtp = new JTabbedPane(JTabbedPane.LEFT); jtp.addTab("Apple", new JLabel("Apple")); jtp.addTab("Banana", new JLabel("Banana")); jtp.addTab("Cherries", new JLabel("Cherries")); jtp.addTab("Grapes", new JLabel("Grapes")); ui.add(jtp, BorderLayout.CENTER); jtp.setPreferredSize(new Dimension(200, 200)); jtp.addChangeListener(e -> {/*from ww w . j av a2 s .com*/ if (e.getSource() instanceof JTabbedPane) { JTabbedPane pane = (JTabbedPane) e.getSource(); System.out.println("Selected paneNo : " + pane.getSelectedIndex()); } }); }
From source file:Main.java
public static void main(String[] argv) { ImageIcon icon = new ImageIcon("image.gif"); MatteBorder matteBorder = (MatteBorder) BorderFactory.createMatteBorder(-1, -1, -1, -1, icon); JLabel component = new JLabel("label"); component.setBorder(matteBorder);// w ww. j a va2s . c om }
From source file:AddingToJScrollPane.java
public static void main(String args[]) { JFrame frame = new JFrame("Tabbed Pane Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel("Label"); label.setPreferredSize(new Dimension(1000, 1000)); JScrollPane jScrollPane = new JScrollPane(label); frame.add(jScrollPane, BorderLayout.CENTER); frame.setSize(400, 150);/*from w w w .j a v a 2 s . c o m*/ frame.setVisible(true); }
From source file:JScrollPaneViewport.java
public static void main(String args[]) { JFrame frame = new JFrame("Tabbed Pane Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel("Label"); label.setPreferredSize(new Dimension(1000, 1000)); JScrollPane jScrollPane = new JScrollPane(); jScrollPane.setViewportView(label);/*from www .j a v a 2 s.c o m*/ frame.add(jScrollPane, BorderLayout.CENTER); frame.setSize(400, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JSlider slider = new JSlider(); Dictionary table = slider.getLabelTable(); ImageIcon icon = new ImageIcon("icon.gif"); JLabel label = new JLabel(icon); // Set at desired positions table.put(new Integer(slider.getMinimum()), label); table.put(new Integer(slider.getMaximum()), label); // Force the slider to use the new labels slider.setLabelTable(table);/*w w w . j a va2 s . co m*/ }
From source file:Main.java
public static void main(String[] args) { JTextField ipField = new JTextField(10); JTextField portField = new JTextField(10); JPanel panel = new JPanel(); panel.add(new JLabel("IP:")); panel.add(ipField);//from www. j ava 2s.c o m panel.add(Box.createHorizontalStrut(15)); panel.add(new JLabel("Port:")); panel.add(portField); int result = JOptionPane.showConfirmDialog(null, panel, "Enter Information", JOptionPane.OK_CANCEL_OPTION); if (result == JOptionPane.OK_OPTION) { System.out.println("IP: " + ipField.getText()); System.out.println("Port: " + portField.getText()); } }