Boa tarde pessoal.
Na minha interface tenho um JSplitPane no qual estou adicionando um JScrollPane juntamente com o JPanel,
porém quando eu vou adicionar uma JComboBox na SplitPane ele fica muito grande e totalmente desproporcional
ao que quero, segue a imagem de como fica:
http://imageshack.us/photo/my-images/849/relatorioscombo.jpg/
Pesquisei algumas coisas mais ainda não consegui dar uma solução a isso, se alguém puder me dar uma forcinha...agradeço. :thumbup:
Obrigado a todos.
Segue o código pra exemplo.
package view;
import java.awt.BorderLayout;
import java.io.File;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JToolBar;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
public class Relatorios extends JFrame {
private JSplitPane splitPane;
private JPanel painel1;
private JPanel painel2;
private JScrollPane scroll1;
private JScrollPane scroll2;
private JToolBar barBotoes = new JToolBar();
private JButton btnInformaParametros = new JButton();
private JButton btnListaRelatorios = new JButton();
private JButton btnMontaRelatorio = new JButton();
private JButton btnVoltar = new JButton();
private DefaultMutableTreeNode rootNode;
private JTree tree;
//private JScrollPane scroll;
private JLabel lblClassifLotesEst = new JLabel();
private JComboBox combo = new JComboBox();
public Relatorios() {
init();
}
public void init() {
this.setTitle("Relatórios");
this.setSize(600, 700);
this.setLocationRelativeTo(null);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setIconImage(new ImageIcon(getClass().getResource("/image/ICONE_TITULO.png")).getImage());
barBotoes.add(btnInformaParametros);
barBotoes.add(btnListaRelatorios);
barBotoes.add(btnMontaRelatorio);
barBotoes.add(btnVoltar);
rootNode = new DefaultMutableTreeNode("Relatórios");
tree = new JTree(rootNode);
scroll1 = new JScrollPane(tree);
scroll1.setBounds(50, 0, 600, 325);
painel1 = new JPanel();
painel1.setLayout(new BorderLayout());
painel1.add(barBotoes, BorderLayout.NORTH);
painel1.add(scroll1);
painel2 = new JPanel();
painel2.setLayout(new BorderLayout());
painel2.add(lblClassifLotesEst, BorderLayout.CENTER);
painel2.add(combo);
combo.setBounds(10, 10, 150, 20);
lblClassifLotesEst.setBorder(BorderFactory.createTitledBorder("Classificação de Lotes Por Estação"));
scroll2 = new JScrollPane(painel2);
barBotoes.setBounds(0, 0, 600, 45);
barBotoes.setFloatable(false);
btnInformaParametros.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/BTS_Relatorios/BT_Informa_Parametros_Selecao.png")));
btnListaRelatorios.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/BTS_Relatorios/BT_Lista_Relatorios.png")));
btnMontaRelatorio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/BTS_Relatorios/BT_Monta_Relatorio.png")));
btnVoltar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/BTS_Relatorios/BT_Voltar.png")));
splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, painel1, scroll2);
splitPane.setDividerLocation(400);
splitPane.setEnabled(false);
getContentPane().add(splitPane);
//Chama o método para popular o JTree
listAllFiles("C:\\Users\\diego\\Desktop\\Relatorios", rootNode, true);
this.setVisible(true);
}
/*
* @params: String directory - o diretório a trabalhar
* @params: DefaultMutableTreeNode parent - o node pai
* @params: Boolean recursive - determina se vai trabalhar com as subpastas, ou só o pai
*/
public static void listAllFiles(String directory, DefaultMutableTreeNode parent, Boolean recursive) {
// Lista todos os arquivos no diretório "String directory" no array "children"
File[] children = new File(directory).listFiles();
for (int i = 0; i < children.length; i++) {
// Pega o nome de cada Pasta ou Arquivo
DefaultMutableTreeNode node = new DefaultMutableTreeNode(children[i].getName());
// Só mostra o Node se ele é uma pasta e se esta é uma chamada recursiva
if (children[i].isDirectory() && recursive) {
parent.add(node); // adiciona como filho
listAllFiles(children[i].getPath(), node, recursive); // chamada recursiva para trabalhar com o filho
} else if (!children[i].isDirectory()) { // senão caso não seja um diretório
parent.add(node); // adiciona como um arquivo
}
}
}
public static void main(String[] args) {
new Relatorios();
}
}
Se caso alguém for rodar ele tem que mudar um caminho que coloque no ListAllFiles.
Abs...