List of usage examples for java.awt BorderLayout BorderLayout
public BorderLayout()
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel outerPanel = new JPanel(new BorderLayout()); JPanel topPanel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name:"); JTextField text = new JTextField(); topPanel.add(label, BorderLayout.LINE_END); topPanel.add(text, BorderLayout.CENTER); outerPanel.add(topPanel, BorderLayout.AFTER_LAST_LINE); frame.add(outerPanel);/*from w ww . jav a 2 s.c om*/ frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel outerPanel = new JPanel(new BorderLayout()); JPanel topPanel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name:"); JTextField text = new JTextField(); topPanel.add(label, BorderLayout.BEFORE_LINE_BEGINS); topPanel.add(text, BorderLayout.CENTER); outerPanel.add(topPanel, BorderLayout.AFTER_LINE_ENDS); frame.add(outerPanel);//from w w w. j a v a 2 s .c om frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel outerPanel = new JPanel(new BorderLayout()); JPanel topPanel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name:"); JTextField text = new JTextField(); topPanel.add(label, BorderLayout.BEFORE_LINE_BEGINS); topPanel.add(text, BorderLayout.CENTER); outerPanel.add(topPanel, BorderLayout.AFTER_LAST_LINE); frame.add(outerPanel);/*from ww w . java 2 s . c om*/ frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { Main t = new Main(); JPanel mainPanel = new JPanel(new BorderLayout()); JLabel l = new JLabel("hello world"); l.setOpaque(true);//from w ww . j a v a 2s . co m l.setBackground(Color.RED); JPanel extraPanel = new JPanel(new FlowLayout()); l.setPreferredSize(new Dimension(100, 100)); extraPanel.setBackground(Color.GREEN); extraPanel.add(l); mainPanel.add(extraPanel, BorderLayout.CENTER); t.setContentPane(mainPanel); t.setDefaultCloseOperation(EXIT_ON_CLOSE); t.setSize(400, 200); t.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel panel = new JPanel(new BorderLayout()); String[] values = new String[] { "One", "Two", "Three" }; JComboBox<String> comboBox = new JComboBox<>(values); panel.add(comboBox, BorderLayout.NORTH); JTextArea textArea = new JTextArea(2, 2); panel.add(textArea, BorderLayout.CENTER); JButton button = new JButton("Action"); button.addActionListener(new ActionListener() { @Override/*from ww w . j a v a 2 s . co m*/ public void actionPerformed(ActionEvent e) { textArea.setText((String) comboBox.getSelectedItem()); comboBox.setSelectedIndex(0); } }); panel.add(button, BorderLayout.SOUTH); JFrame frame = new JFrame(); frame.add(panel); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:MainFrameBorderLayout.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel outerPanel = new JPanel(new BorderLayout()); JPanel topPanel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name:"); JTextField text = new JTextField(); topPanel.add(label, BorderLayout.BEFORE_LINE_BEGINS); topPanel.add(text, BorderLayout.CENTER); outerPanel.add(topPanel, BorderLayout.BEFORE_FIRST_LINE); frame.add(outerPanel);/* ww w . ja va 2s . c o m*/ frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) throws Exception { 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 . j av a2 s.c om*/ 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); textField.setText("your text"); String filename = "test.txt"; FileWriter writer = new FileWriter(filename); textField.write(writer); writer.close(); }
From source file:Main.java
public static void main(String[] args) { int specificX = 40; int specificY = 20; JPanel gui = new JPanel(new BorderLayout()); JTextField tf = new JTextField(10); JPanel borderPanel = new JPanel(new GridLayout()); borderPanel.add(tf);//from www. j a v a2s.co m borderPanel.setBorder(new EmptyBorder(specificX, specificY, specificX, specificY)); borderPanel.setBackground(Color.GREEN); gui.add(borderPanel); JOptionPane.showMessageDialog(null, gui); }
From source file:Main.java
public static void main(String[] args) { Image image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); JPanel gui = new JPanel(new BorderLayout()); JLabel clouds = new JLabel(new ImageIcon(new BufferedImage(250, 100, BufferedImage.TYPE_INT_RGB))); gui.add(clouds);/*w w w. ja va 2s . c o m*/ JOptionPane.showConfirmDialog(null, gui, "Title", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, new ImageIcon(image)); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name: "); label.setDisplayedMnemonic(KeyEvent.VK_N); JTextField textField = new JTextField(); textField.setHorizontalAlignment(JTextField.CENTER); label.setLabelFor(textField);/*from w w w . j ava 2 s. c om*/ panel.add(label, BorderLayout.WEST); panel.add(textField, BorderLayout.CENTER); frame.add(panel, BorderLayout.NORTH); frame.setSize(250, 150); frame.setVisible(true); }