Jump to content

Parte Grafica


AJBM

Recommended Posts

Boas!

Eu queria saber como é que posso por os botões, Painel seguinte e mensagem mais em baixo, eles estão do lado esquerdo só que estão muito em cima é possível coloca los mais em baixo?

public Grafica() {
    initComponents();
    final JPanel p1 = new JPanel();
    final JPanel dentrodop1 = new JPanel();
    final JPanel contempaineis = new JPanel(new CardLayout());
    final JPanel p2 = new JPanel(new BorderLayout());
    final JPanel dentrop1_2= new JPanel();
    final JPanel dentrodop2=new JPanel();
    final JRadioButton escolha= new JRadioButton("Escolhe: ");
    this.setSize(1000, 1000);
    JButton b = new JButton("Painel seguinte");
    JButton a = new JButton("Button");
    JButton button = new JButton("Mensagem");
    JTextArea ta = new JTextArea(10, 10);
    JScrollPane barra = new JScrollPane(ta);
    barra.setHorizontalScrollBarPolicy(barra.HORIZONTAL_SCROLLBAR_NEVER);
    barra.setVerticalScrollBarPolicy(barra.VERTICAL_SCROLLBAR_ALWAYS);
    this.setLayout(new BorderLayout());
    p1.setLayout(new BorderLayout());
    dentrodop1.setLayout(new BoxLayout(dentrodop1,BoxLayout.Y_AXIS));
    dentrop1_2.setLayout(new BoxLayout(dentrop1_2, BoxLayout.X_AXIS));

    dentrodop1.add(b);
    dentrodop1.add(button);

    dentrop1_2.add(barra);
    dentrodop2.add(escolha);
    dentrodop2.add(a);

    p1.add(dentrodop1,BorderLayout.WEST);
    p1.add(dentrop1_2,BorderLayout.CENTER);
    p2.add(dentrodop2,BorderLayout.WEST);
    contempaineis.add(p1, "Painel1");
    contempaineis.add(p2, "Painel2");
    this.add(contempaineis);

    b.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            CardLayout card = (CardLayout) contempaineis.getLayout();
            card.show(contempaineis, "Painel2");

        }
    });

    a.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

                CardLayout card = (CardLayout) contempaineis.getLayout();
            card.show(contempaineis, "Painel1");
        }
    });

}
Link to comment
Share on other sites

Boas!! é o codigo todo que fiz

import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextPane;
/**
*
* @author Antonio
*/
public class Grafica extends javax.swing.JFrame {
   public Grafica() {
       initComponents();

       final JPanel p1 = new JPanel();
       final JPanel dentrodop1 = new JPanel();
       final JPanel contempaineis = new JPanel(new CardLayout());
       final JPanel p2 = new JPanel(new BorderLayout());
       final JPanel dentrop1_2 = new JPanel();
       final JPanel dentrodop2 = new JPanel();
       final JPanel vazio = new JPanel();
       final JRadioButton escolha = new JRadioButton("Escolhe: ");
       final JButton nvisivel = new JButton();
       JButton b = new JButton("Painel seguinte");
       JButton a = new JButton("Button");
       JButton button = new JButton("Mensagem");
       JTextArea ta = new JTextArea(10, 10);
       JScrollPane barra = new JScrollPane(ta);
       nvisivel.setVisible(false);
       this.setSize(500, 500);

       barra.setHorizontalScrollBarPolicy(barra.HORIZONTAL_SCROLLBAR_NEVER);
       barra.setVerticalScrollBarPolicy(barra.VERTICAL_SCROLLBAR_ALWAYS);
       this.setLayout(new BorderLayout());
       this.setTitle("Teste");
       p1.setLayout(new BorderLayout());
       dentrodop1.setLayout(new BoxLayout(dentrodop1, BoxLayout.Y_AXIS));
       dentrop1_2.setLayout(new BoxLayout(dentrop1_2, BoxLayout.X_AXIS));
       dentrodop1.add(b);
       dentrodop1.add(button);
       dentrop1_2.add(barra);
       dentrodop2.add(escolha);
       dentrodop2.add(a);

       p1.add(dentrodop1, BorderLayout.WEST);
       p1.add(dentrop1_2, BorderLayout.CENTER);
       p1.add(vazio, BorderLayout.PAGE_START);
       p2.add(dentrodop2, BorderLayout.WEST);
       contempaineis.add(p1, "Painel1");
       contempaineis.add(p2, "Painel2");
       this.add(contempaineis);

       b.addActionListener(new ActionListener() {
           @Override
           public void actionPerformed(ActionEvent e) {

               CardLayout card = (CardLayout) contempaineis.getLayout();
               card.show(contempaineis, "Painel2");

           }
       });

       a.addActionListener(new ActionListener() {
           @Override
           public void actionPerformed(ActionEvent e) {
               CardLayout card = (CardLayout) contempaineis.getLayout();
               card.show(contempaineis, "Painel1");
           }
       });

   }
   /**
    * This method is called from within the constructor to initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is always
    * regenerated by the Form Editor.
    */
   @SuppressWarnings("unchecked")
   // <editor-fold defaultstate="collapsed" desc="Generated Code">                         
   private void initComponents() {
       setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
       javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
       getContentPane().setLayout(layout);
       layout.setHorizontalGroup(
           layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
           .addGap(0, 400, Short.MAX_VALUE)
       );
       layout.setVerticalGroup(
           layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
           .addGap(0, 300, Short.MAX_VALUE)
       );
       pack();
   }// </editor-fold>                       
   /**
    * @param args the command line arguments
    */
   public static void main(String args[]) {
       /* Set the Nimbus look and feel */
       //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
       /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
        * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
        */
       try {
           for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
               if ("Nimbus".equals(info.getName())) {
                   javax.swing.UIManager.setLookAndFeel(info.getClassName());
                   break;
               }
           }
       } catch (ClassNotFoundException ex) {
           java.util.logging.Logger.getLogger(Grafica.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
       } catch (InstantiationException ex) {
           java.util.logging.Logger.getLogger(Grafica.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
       } catch (IllegalAccessException ex) {
           java.util.logging.Logger.getLogger(Grafica.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
       } catch (javax.swing.UnsupportedLookAndFeelException ex) {
           java.util.logging.Logger.getLogger(Grafica.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
       }
       //</editor-fold>
       /* Create and display the form */
       java.awt.EventQueue.invokeLater(new Runnable() {
           public void run() {
               new Grafica().setVisible(true);
           }
       });
   }
   // Variables declaration - do not modify                    
   // End of variables declaration                  
}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.