Hallo,
ich möchte das der JTree mindestens den Platz des ScrollPanes nutzt und falls er mehr braucht
soll er auch größer sein.
SetMinimumSize() wird ignoriert und bei setPreferredSize() wird er nicht größer, wenn der Platzt des ScrollPanes ausgeht.
Hat jemand eine Idee wie ich das machen kann?
ich möchte das der JTree mindestens den Platz des ScrollPanes nutzt und falls er mehr braucht
soll er auch größer sein.
SetMinimumSize() wird ignoriert und bei setPreferredSize() wird er nicht größer, wenn der Platzt des ScrollPanes ausgeht.
Hat jemand eine Idee wie ich das machen kann?
Java:
public class Test {
public Test(){
JFrame f = new JFrame("Test");
f.setSize(820, 600);
JPanel pView1=new JPanel();
//pView1.setLayout(new BoxLayout(pView1, BoxLayout.Y_AXIS));
pView1.setLayout(new BorderLayout(0,0));
JMenuBar switchViews= new JMenuBar();
JMenuItem item= new JMenuItem("View1");
switchViews.add(item);
item= new JMenuItem("View2");
switchViews.add(item);
f.setJMenuBar(switchViews);
JPanel pTop= new JPanel();
pTop.setLayout(new FlowLayout(FlowLayout.LEFT));
JTextField tf=new JTextField();
tf.setColumns(15);
JLabel label=new JLabel("Label:");
pTop.add(label);pTop.add(tf);
pView1.add(pTop,BorderLayout.NORTH);
JPanel pRight=new JPanel();
pRight.setLayout(new BoxLayout(pRight, BoxLayout.Y_AXIS));
JScrollPane pLeft=new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
pLeft.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);//Scrollbar auf der LinkenSeite
JSplitPane sp=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,pLeft,pRight);
sp.setDividerLocation(310);
pView1.add(sp);
JFileChooser fc = new JFileChooser();
fc.setControlButtonsAreShown(false);
pRight.add(fc);
JPanel pCreate=new JPanel();
pCreate.setLayout(new BoxLayout(pCreate, BoxLayout.Y_AXIS));
JPanel pButtons=new JPanel();
JButton create=new JButton("Create");
pButtons.add(create);
JButton reset=new JButton("Reset");
pButtons.add(reset);
pCreate.add(pButtons);
pView1.add(pCreate,BorderLayout.SOUTH);
JPanel pDirectories=new JPanel();
pDirectories.setAlignmentX(Component.LEFT_ALIGNMENT);
DefaultMutableTreeNode root=new DefaultMutableTreeNode("Ordner-Struktur");
for(int i=0;i<3;i++){
DefaultMutableTreeNode node=new DefaultMutableTreeNode("Ordner"+i);
for(int l=0;l<3;l++){
DefaultMutableTreeNode blatt=new DefaultMutableTreeNode("blatt");
node.add(blatt);
}
root.add(node);
}
JTree DirectoryStructure= new JTree(root);
DirectoryStructure.setAlignmentX(Component.LEFT_ALIGNMENT);
DirectoryStructure.setMinimumSize(new Dimension(100,100));
for(int row=1;row<DirectoryStructure.getRowCount();row++){
DirectoryStructure.expandRow(row);
}
pDirectories.add(DirectoryStructure);
pLeft.getViewport().add(pDirectories);
f.add(pView1);
f.setVisible(true);
}
public static void main(String[] args) {
new Test();
}
}
