Guest User

Untitled

a guest
Dec 3rd, 2016
75
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.awt.BorderLayout;
  2. import java.awt.Dimension;
  3.  
  4. import javax.swing.JButton;
  5. import javax.swing.JComponent;
  6. import javax.swing.JFrame;
  7. import javax.swing.JLabel;
  8. import javax.swing.JPanel;
  9. import javax.swing.JTabbedPane;
  10. import javax.swing.BorderFactory;
  11.  
  12. public class Tela extends JFrame {
  13.  
  14.     JTabbedPane tabbedPane = new JTabbedPane();
  15.  
  16.     public Tela() {
  17.         setTitle("Apenas um EXEMPLO");
  18.         tabbedPane.addTab("Página 1", painel1());
  19.         tabbedPane.addTab("Página 2", painel2());
  20.         tabbedPane.setPreferredSize(new Dimension(getWidth(), 150));
  21.  
  22.         /* -- exemplificacao de como adicionar o painel superior -- */
  23.         JPanel painelSuperior = new JPanel();
  24.         painelSuperior.setBorder(BorderFactory.createTitledBorder("painel superior"));
  25.         painelSuperior.add(new JButton("teste"));
  26.         add(painelSuperior, BorderLayout.NORTH);
  27.         /* -- exemplificacao de como adicionar o painel inferior -- */
  28.         JPanel painelInferior = new JPanel();
  29.         painelInferior.setBorder(BorderFactory.createTitledBorder("painel inferior"));
  30.         painelInferior.add(new JButton("teste"));
  31.         add(painelInferior, BorderLayout.SOUTH);
  32.         /* -- tabbedPane adicionado no centro da tela -- */
  33.         add(tabbedPane, BorderLayout.CENTER);
  34.         setResizable(false);
  35.         setSize(600, 500);
  36.         setMinimumSize(new Dimension(getWidth(), getHeight()));
  37.         pack();
  38.         setVisible(true);
  39.         setLocationRelativeTo(null);
  40.         setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  41.     }
  42.  
  43.     public static void main(String[] args) {
  44.         Tela tela  = new Tela();
  45.     }
  46.  
  47.     public JComponent painel1() {
  48.         JPanel painel1 = new JPanel();      
  49.         JLabel label1;    
  50.         label1 = new JLabel("Página 1");
  51.         painel1.add(label1);
  52.         return painel1; // retorna painel.
  53.     }
  54.  
  55.     public JComponent painel2() {
  56.         JPanel painel2 = new JPanel();      
  57.         JLabel label2;
  58.         label2 = new JLabel("Página 2");
  59.         painel2.add(label2);
  60.         return painel2;
  61.     }
  62. }
RAW Paste Data