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 dialog = new JFrame(); dialog.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); dialog.setResizable(true);//from w w w . j av a 2 s.c o m JPanel guiHolder = new JPanel(); guiHolder.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.anchor = GridBagConstraints.PAGE_START; gbc.weightx = 1.0; gbc.weighty = 1.0; guiHolder.add(new JLabel("my test"), gbc); dialog.add(guiHolder); dialog.setSize(new Dimension(320, 240)); dialog.setVisible(true); }
From source file:ChangingTitleBorderDirection.java
public static void main(String args[]) { JFrame frame = new JFrame("Sample Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border lineBorder = new LineBorder(Color.RED, 5); Font font = new Font("Serif", Font.ITALIC, 12); Border titledBorder = new TitledBorder(lineBorder, "Hello", TitledBorder.LEFT, TitledBorder.BELOW_BOTTOM, font, Color.RED);/* w ww . j ava2s. c o m*/ JLabel aLabel = new JLabel("Bevel"); aLabel.setBorder(titledBorder); aLabel.setHorizontalAlignment(JLabel.CENTER); frame.add(aLabel); frame.setSize(400, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JComboBox<String> comboBox = new JComboBox<>(new String[] { "A", "B", "C" }); comboBox.setEditable(true);/*from w w w.j av a2 s.c o m*/ JTextField editorComponent = (JTextField) comboBox.getEditor().getEditorComponent(); editorComponent.addActionListener(e -> { editorComponent.transferFocus(); }); JPanel panel = new JPanel(new FlowLayout()); panel.add(new JLabel("Field 1")); panel.add(comboBox); panel.add(new JLabel("Field 2")); panel.add(new JTextField(10)); panel.add(new JLabel("Field 3")); panel.add(new JTextField(10)); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); Container c = frame.getContentPane(); c.setLayout(new BorderLayout()); c.add(panel, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(Main.class.getSimpleName()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JButton button = new JButton("Click me to open dialog"); button.addActionListener(e -> {// w w w . j av a2s. c o m Window parentWindow = SwingUtilities.windowForComponent(button); JDialog dialog = new JDialog(parentWindow); dialog.setLocationRelativeTo(button); dialog.setModal(true); dialog.add(new JLabel("A dialog")); dialog.pack(); dialog.setVisible(true); }); frame.add(button); frame.pack(); frame.setVisible(true); }
From source file:LabelTextPos.java
public static void main(String args[]) { JFrame frame = new JFrame("Label Text Pos"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = frame.getContentPane(); content.setLayout(new GridLayout(2, 2)); Border border = LineBorder.createGrayLineBorder(); Icon warnIcon = new ImageIcon("Warn.gif"); JLabel label1 = new JLabel(warnIcon); label1.setText("Left-Bottom"); label1.setHorizontalTextPosition(JLabel.LEFT); label1.setVerticalTextPosition(JLabel.BOTTOM); label1.setBorder(border);//from w w w .j ava 2 s . c o m content.add(label1); JLabel label2 = new JLabel(warnIcon); label2.setText("Right-TOP"); label2.setHorizontalTextPosition(JLabel.RIGHT); label2.setVerticalTextPosition(JLabel.TOP); label2.setBorder(border); content.add(label2); JLabel label3 = new JLabel(warnIcon); label3.setText("Center-Center"); label3.setHorizontalTextPosition(JLabel.CENTER); label3.setVerticalTextPosition(JLabel.CENTER); label3.setBorder(border); content.add(label3); JLabel label4 = new JLabel(warnIcon); label4.setText("Center-Bottom"); label4.setHorizontalTextPosition(JLabel.CENTER); label4.setVerticalTextPosition(JLabel.BOTTOM); label4.setBorder(border); content.add(label4); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setUndecorated(true);/*from www . j av a2 s . co m*/ frame.setBackground(new Color(0, 0, 0, 0)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(new ShadowPane()); JPanel panel = new JPanel(new GridBagLayout()); panel.add(new JLabel("Look ma, no hands")); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:TripleListSample.java
public static void main(String args[]) { String labels[] = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }; JFrame f = new JFrame("Selection Modes"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList list1 = new JList(labels); JList list2 = new JList(labels); JList list3 = new JList(labels); Container c = f.getContentPane(); JScrollPane sp1 = new JScrollPane(list1); sp1.setColumnHeaderView(new JLabel("Single Selection")); JScrollPane sp2 = new JScrollPane(list2); sp2.setColumnHeaderView(new JLabel("Single Interval")); JScrollPane sp3 = new JScrollPane(list3); sp3.setColumnHeaderView(new JLabel("Multi Interval")); Box box = Box.createHorizontalBox(); box.add(sp1);//from w w w. j av a2 s .co m box.add(sp2); box.add(sp3); c.add(box, BorderLayout.CENTER); f.setSize(300, 200); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String TITLE = "Full Screen Test"; JFrame f = new JFrame(TITLE); JDesktopPane jdp = new JDesktopPane(); GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice dev = env.getDefaultScreenDevice(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JInternalFrame jif = new JInternalFrame(TITLE, true, true, true); jif.add(new JLabel(TITLE + " " + TITLE), BorderLayout.NORTH); jif.add(new JLabel(TITLE + " " + TITLE), BorderLayout.CENTER); jif.add(new JLabel(TITLE + " " + TITLE), BorderLayout.SOUTH); jif.pack();//from w w w. jav a 2s . co m jif.setLocation(100, 100); jif.setVisible(true); jdp.add(jif); f.add(jdp, BorderLayout.CENTER); dev.setFullScreenWindow(f); }
From source file:Main.java
public static void main(String[] args) { final JFrame frame = new JFrame(); JOptionPane pane = new JOptionPane("Some message", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION) { @Override//from ww w . ja va 2 s.c om public void setValue(Object newValue) { super.setValue(newValue); JOptionPane.showMessageDialog(frame.getContentPane(), "You have hit " + newValue); } }; frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new JLabel("Some panel in the middle"), BorderLayout.CENTER); frame.add(pane, BorderLayout.SOUTH); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JRadioButton button1 = new JRadioButton("Red"); JRadioButton button2 = new JRadioButton("Green"); JRadioButton button3 = new JRadioButton("Blue"); ButtonGroup colorButtonGroup = new ButtonGroup(); colorButtonGroup.add(button1);//from w ww . j a v a 2s.c o m colorButtonGroup.add(button2); colorButtonGroup.add(button3); JFrame frame = new JFrame(); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JLabel("Color:")); frame.add(button1); frame.add(button2); frame.add(button3); frame.pack(); frame.setVisible(true); }