Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. public class Test extends JFrame {
  2.  
  3. private JButton btn;
  4. private JPanel painel;
  5. private JScrollPane scroll;
  6. private JTextArea tArea;
  7.  
  8. public Test() {
  9.  
  10. btn = new JButton("Sair");
  11. btn.setPreferredSize(new Dimension(72, 35));
  12. btn.addActionListener(e -> System.exit(0));
  13.  
  14. painel = new JPanel();
  15. painel.add(btn, FlowLayout.LEFT); //nao funciona
  16.  
  17. JScrollPane scroll = new JScrollPane(tArea = new JTextArea());
  18. scroll.setPreferredSize(new Dimension(400, 300));
  19. scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
  20.  
  21. Container cp = getContentPane();
  22. cp.add(painel, "North");
  23. cp.add(scroll, "Center");
  24.  
  25. getRootPane().setDefaultButton(btn);
  26.  
  27. setSize(400, 280);
  28. setLocationRelativeTo(null);
  29. setDefaultCloseOperation(EXIT_ON_CLOSE);
  30. }
  31.  
  32. public static void main(String[] args) {
  33. new Test().setVisible(true);
  34. }
  35.  
  36. }
  37.  
  38. painel = new JPanel();
  39. FlowLayout layout = (FlowLayout) painel.getLayout();
  40. layout.setAlignment(FlowLayout.LEFT);
  41. painel.add(btn);
  42.  
  43. ((FlowLayout)painel.getLayout()).setAlignment(FlowLayout.LEFT);
  44.  
  45. painel = new JPanel(new FlowLayout(FlowLayout.LEFT));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement