diegogm
Setembro 24, 2012, 8:09am
#1
Bom dia galera!
Preciso de uma ajuda, pesquisei no Google vi varias coisas sobre vi até uns tutoriais aqui no GUJ mais não estou conseguindo colocar dentro do meu JPanel
2 JTable. Tenho um JFrame adicionei a ele um JPanel dentro do panel tem uma barra de menu, uma barra de botões, um label e um textfield, pois bem preciso
agora colocar 2 JTable uma do lado da outra como mostra na imagem abaixo:
Vou postar o código que fiz até agora para vcs verem.
[code]package view;
import java.awt.Dimension;
import java.awt.event.KeyEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.WindowConstants;
public class AbMudancaDistribuicao extends JFrame {
private JPanel painel;
private JMenuBar BarraMudanca;
private JMenu MnMudancaDistribuicao;
private JMenu MnVoltar;
private JMenuItem MiPropagacao;
private JToolBar barBotao1;
private JButton btnPropagaMudanca;
private JButton btnVoltar;
private JLabel lblIdentificaProjeto;
private JLabel lblMensagem;
private JTextField txtIdentificaProjeto;
public AbMudancaDistribuicao() {
init();
}
private void init() {
this.setTitle("Mudança de Distribuição");
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.setSize(800, 600);
this.setVisible(true);
this.setJMenuBar(getBarraMudanca());
painel = new JPanel();
painel.setLayout(null);
painel.setSize(800, 600);
this.add(painel);
barBotao1 = new JToolBar();
barBotao1.setBounds(0, 0, 100, 45);
barBotao1.setFloatable(false);
btnPropagaMudanca = new JButton();
btnPropagaMudanca.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/BT_LIBERAFACILIDADE.png")));
btnVoltar = new JButton();
btnVoltar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/BT_VOLTAR.png")));
lblIdentificaProjeto = new JLabel();
lblIdentificaProjeto.setText("Identifica Projeto");
lblIdentificaProjeto.setBounds(10, 60, 100, 20);
txtIdentificaProjeto = new JTextField();
txtIdentificaProjeto.setBounds(110, 60, 300, 20);
//lblMensagem = new JLabel();
barBotao1.add(btnPropagaMudanca);
barBotao1.add(btnVoltar);
painel.add(barBotao1);
painel.add(lblIdentificaProjeto);
painel.add(txtIdentificaProjeto);
//painel.add(lblMensagem);
}
private JMenuBar getBarraMudanca() {
if (BarraMudanca == null) {
BarraMudanca = new JMenuBar();
BarraMudanca.add(getMnMudancaDistribuicao());
BarraMudanca.add(getMnVoltar());
}
return BarraMudanca;
}
private JMenu getMnMudancaDistribuicao() {
if (MnMudancaDistribuicao == null) {
MnMudancaDistribuicao = new JMenu();
MnMudancaDistribuicao.setText("Mudança de Distribuição");
MnMudancaDistribuicao.setMnemonic(KeyEvent.VK_M);
MnMudancaDistribuicao.add(getMiPropagacao());
}
return MnMudancaDistribuicao;
}
private JMenuItem getMiPropagacao() {
if (MiPropagacao == null) {
MiPropagacao = new JMenuItem();
MiPropagacao.setText("Propagação");
}
return MiPropagacao;
}
private JMenu getMnVoltar() {
if (MnVoltar == null) {
MnVoltar = new JMenu();
MnVoltar.setText("Voltar");
MnVoltar.setMnemonic(KeyEvent.VK_V);
}
return MnVoltar;
}
public static void main(String[] args) {
new AbMudancaDistribuicao();
}
}
[/code]
Obrigado a todos pela ajuda!
odney
Setembro 24, 2012, 10:39am
#2
Boa tarde.
Acho que é mais ou menos isso que você quer.
Estou sem tempo para formatar, mas o caminho é esse, use GridBagConstraints.
Existem vários tutoriais, se precisar alterar mais para cima ou baixo, centralizar, posta, que a noite respondo.
abraço.
package view;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.KeyEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.WindowConstants;
public class AbMudancaDistribuicao extends JFrame {
private JPanel painel;
private JMenuBar BarraMudanca;
private JMenu MnMudancaDistribuicao;
private JMenu MnVoltar;
private JMenuItem MiPropagacao;
private JToolBar barBotao1;
private JButton btnPropagaMudanca;
private JButton btnVoltar;
private JLabel lblIdentificaProjeto;
private JLabel lblMensagem;
private JTextField txtIdentificaProjeto;
public AbMudancaDistribuicao() {
init();
}
private void init() {
GridBagConstraints gbcBase = new GridBagConstraints();////
this.setLayout(new GridBagLayout());////
this.setTitle("Mudança de Distribuição");
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.setPreferredSize(new Dimension(800,600));
this.setMinimumSize(this.getPreferredSize());
this.setMaximumSize(this.getPreferredSize());
//this.setSize(800, 600);
this.setVisible(true);
this.setJMenuBar(getBarraMudanca());
painel = new JPanel();
painel.setLayout(new GridBagLayout());
painel.setPreferredSize(new Dimension(800,600));
painel.setMinimumSize(painel.getPreferredSize());
painel.setMaximumSize(painel.getPreferredSize());
//painel.setBackground(Color.BLACK);
//painel.setSize(800, 600);
this.add(painel,gbcBase);
barBotao1 = new JToolBar();
//barBotao1.setBounds(0, 0, 100, 45);
barBotao1.setPreferredSize(new Dimension(600, 45));
barBotao1.setMinimumSize(barBotao1.getPreferredSize());
barBotao1.setMaximumSize(barBotao1.getPreferredSize());
barBotao1.setFloatable(false);
btnPropagaMudanca = new JButton();
btnPropagaMudanca.setPreferredSize(new Dimension(30, 20));
btnPropagaMudanca.setMinimumSize(btnPropagaMudanca.getPreferredSize());
btnPropagaMudanca.setMaximumSize(btnPropagaMudanca.getPreferredSize());
//btnPropagaMudanca.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/BT_LIBERAFACILIDADE.png")));
btnVoltar = new JButton();
btnVoltar.setPreferredSize(new Dimension(30,20));
btnVoltar.setMinimumSize(btnVoltar.getPreferredSize());
btnVoltar.setMaximumSize(btnVoltar.getPreferredSize());
//btnVoltar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/BT_VOLTAR.png")));
lblIdentificaProjeto = new JLabel();
lblIdentificaProjeto.setText("Identifica Projeto");
//lblIdentificaProjeto.setBounds(10, 60, 100, 20);
lblIdentificaProjeto.setPreferredSize(new Dimension(100, 20));
lblIdentificaProjeto.setMinimumSize(lblIdentificaProjeto.getPreferredSize());
lblIdentificaProjeto.setMaximumSize(lblIdentificaProjeto.getPreferredSize());
txtIdentificaProjeto = new JTextField();
//txtIdentificaProjeto.setBounds(110, 60, 300, 20);
txtIdentificaProjeto.setPreferredSize(new Dimension(300, 20));
txtIdentificaProjeto.setMinimumSize(txtIdentificaProjeto.getPreferredSize());
txtIdentificaProjeto.setMaximumSize(txtIdentificaProjeto.getPreferredSize());
//lblMensagem = new JLabel();
barBotao1.add(btnPropagaMudanca,gbcBase);
gbcBase.gridx = 2;
barBotao1.add(btnVoltar,gbcBase);
gbcBase.gridx = 1;
gbcBase.gridwidth = 2;
painel.add(barBotao1,gbcBase);
gbcBase.gridwidth = 1;
gbcBase.gridy = 2;
painel.add(lblIdentificaProjeto,gbcBase);
gbcBase.gridx = 2;
painel.add(txtIdentificaProjeto,gbcBase);
//painel.add(lblMensagem);
}
private JMenuBar getBarraMudanca() {
if (BarraMudanca == null) {
BarraMudanca = new JMenuBar();
BarraMudanca.add(getMnMudancaDistribuicao());
BarraMudanca.add(getMnVoltar());
}
return BarraMudanca;
}
private JMenu getMnMudancaDistribuicao() {
if (MnMudancaDistribuicao == null) {
MnMudancaDistribuicao = new JMenu();
MnMudancaDistribuicao.setText("Mudança de Distribuição");
MnMudancaDistribuicao.setMnemonic(KeyEvent.VK_M);
MnMudancaDistribuicao.add(getMiPropagacao());
}
return MnMudancaDistribuicao;
}
private JMenuItem getMiPropagacao() {
if (MiPropagacao == null) {
MiPropagacao = new JMenuItem();
MiPropagacao.setText("Propagação");
}
return MiPropagacao;
}
private JMenu getMnVoltar() {
if (MnVoltar == null) {
MnVoltar = new JMenu();
MnVoltar.setText("Voltar");
MnVoltar.setMnemonic(KeyEvent.VK_V);
}
return MnVoltar;
}
public static void main(String[] args) {
new AbMudancaDistribuicao();
}
}