AJBM Posted August 19, 2012 at 11:34 AM Report Share #472828 Posted August 19, 2012 at 11:34 AM 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 More sharing options...
Guest skinie18 Posted August 19, 2012 at 03:30 PM Report Share #472837 Posted August 19, 2012 at 03:30 PM http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html Link to comment Share on other sites More sharing options...
AJBM Posted August 19, 2012 at 06:28 PM Author Report Share #472847 Posted August 19, 2012 at 06:28 PM Boas! Eu já tive a ler essa documentação mas mesmo assim ainda não consegui fazer o que queria. Link to comment Share on other sites More sharing options...
Guest skinie18 Posted August 19, 2012 at 07:44 PM Report Share #472851 Posted August 19, 2012 at 07:44 PM Boas! Eu já tive a ler essa documentação mas mesmo assim ainda não consegui fazer o que queria. Desculpa mas nem consigo testar, tem ai código omitido. Link to comment Share on other sites More sharing options...
AJBM Posted August 19, 2012 at 09:15 PM Author Report Share #472852 Posted August 19, 2012 at 09:15 PM 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 More sharing options...
carvalho2707 Posted August 22, 2012 at 07:07 PM Report Share #473179 Posted August 22, 2012 at 07:07 PM olha, recentemente fiz um programa em que usei isso.. acho que nao é intuitivo dar te codigo, o eclipse tem o swing, que com drag-drop consegues facilmente criar botoes, etc.. o melhor de tudo é que ele cria o codigo necessario para aquilo existir 😉 Link to comment Share on other sites More sharing options...
AJBM Posted August 23, 2012 at 09:34 AM Author Report Share #473222 Posted August 23, 2012 at 09:34 AM Eu sei, o netbeans tambem faz isso, mas queria saber como fazer mesmo o código Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now