Hi,

package guiInt;

import java.awt.*;
import javax.swing.*;
import javax.swing.tree.*;



public class Init {
	
	public Init()
	{
		
	}
	
	void buildFrame()
	{
		JFrame window = new JFrame();
		window.setTitle("Pos Setup Tool 0.1 Alfa");
		window.setSize(800, 600);
		window.setResizable(false);
		
		JPanel sidebar = new JPanel(new GridBagLayout());
		sidebar.setPreferredSize(new Dimension(250, 600));
		sidebar.setBackground(Color.black);
		
		JTree tree = buildTree();
		JScrollPane sidebar_placement = new JScrollPane(tree);
		
		sidebar.add(sidebar_placement);
		window.add(sidebar, BorderLayout.WEST);
		window.setVisible(true);		
	}
	
	
	JTree buildTree()
	{
		DefaultMutableTreeNode root = new DefaultMutableTreeNode("Module Browser");
		
		//Towers
		DefaultMutableTreeNode towers = new DefaultMutableTreeNode("Control Tower's");
			DefaultMutableTreeNode towers_gallente = new DefaultMutableTreeNode("Gallente Control Tower's");
				DefaultMutableTreeNode towers_gallente_l = new DefaultMutableTreeNode("Gallente Large Control Tower");
				DefaultMutableTreeNode towers_gallente_m = new DefaultMutableTreeNode("Gallente Medium  Control Tower");
				DefaultMutableTreeNode towers_gallente_s = new DefaultMutableTreeNode("Gallente Small Control Tower");
					towers_gallente.add(towers_gallente_l);
					towers_gallente.add(towers_gallente_m);
					towers_gallente.add(towers_gallente_s);
			DefaultMutableTreeNode towers_caldari = new DefaultMutableTreeNode("Caldari Control Tower's");
				DefaultMutableTreeNode towers_caldari_l = new DefaultMutableTreeNode("Caldari Large Control Tower");
				DefaultMutableTreeNode towers_caldari_m = new DefaultMutableTreeNode("Caldari Medium  Control Tower");
				DefaultMutableTreeNode towers_caldari_s = new DefaultMutableTreeNode("Caldari Small Control Tower");
					towers_caldari.add(towers_caldari_l);
					towers_caldari.add(towers_caldari_m);
					towers_caldari.add(towers_caldari_s);
			DefaultMutableTreeNode towers_amarr = new DefaultMutableTreeNode("Amarr Control Tower's");
				DefaultMutableTreeNode towers_amarr_l = new DefaultMutableTreeNode("Amarr Large Control Tower");
				DefaultMutableTreeNode towers_amarr_m = new DefaultMutableTreeNode("Amarr Medium  Control Tower");
				DefaultMutableTreeNode towers_amarr_s = new DefaultMutableTreeNode("Amarr Small Control Tower");
					towers_amarr.add(towers_amarr_l);
					towers_amarr.add(towers_amarr_m);
					towers_amarr.add(towers_amarr_s);
			DefaultMutableTreeNode towers_minmatar = new DefaultMutableTreeNode("Minmatar Control Tower's");
				DefaultMutableTreeNode towers_minmatar_l = new DefaultMutableTreeNode("Minmatar Large Control Tower");
				DefaultMutableTreeNode towers_minmatar_m = new DefaultMutableTreeNode("Minmatar Medium  Control Tower");
				DefaultMutableTreeNode towers_minmatar_s = new DefaultMutableTreeNode("Minmatar Small Control Tower");
					towers_minmatar.add(towers_minmatar_l);
					towers_minmatar.add(towers_minmatar_m);
					towers_minmatar.add(towers_minmatar_s);
			DefaultMutableTreeNode towers_faction = new DefaultMutableTreeNode("Faction Control Tower's");
				towers.add(towers_amarr);
				towers.add(towers_caldari);
				towers.add(towers_gallente);
				towers.add(towers_minmatar);
				towers.add(towers_faction);
				
		root.add(towers);
		JTree content = new JTree(root);
		return content;
	}
	

		
}

Hello, i am building up a small app for personal use it involves GUI interface i am fairly new to Java i never used it for GUI but i absolutely love its simplicity.

Anyhow here is my problem i want my main GUI window to be split between a "sidebar" and "main content" JPanel. I had problems setting size for the "sidebar" but i got around that whit "setPreferedSize()".

But my JScrollPane and JTree just ignore all methods for resizing them i tried setSize(), setMinimumSize() and setPreferedSize().

My sidebar is the size of 300x600 and i need my JScrollPanel and JTree to strech to the border be the same width and heigth. Only option that has any effect is setPreferedSize() but it just shrinks both containers down to 10x10

Thanks for help,
sorry for the long read : P

mKorbel commented: it's so easy when you posting http://sscce.org/ +9

help me what wont JTree and JScrollBar take .setSize() or .setMinimumSize() or .setPreferedSize() seriously : P

JFrame window = new JFrame();
        window.setTitle("Pos Setup Tool 0.1 Alfa");
        //window.setSize(800, 600);
        window.setResizable(false);

        JPanel sidebar = new JPanel(new BorderLayout());
        sidebar.setPreferredSize(new Dimension(250, 600));
        sidebar.setBackground(Color.black);

        JTree tree = buildTree();
        JScrollPane sidebar_placement = new JScrollPane(tree);

        sidebar.add(sidebar_placement);
        window.add(sidebar, BorderLayout.CENTER);
        window.pack();
        window.setVisible(true);

I love you thank

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.