0

im trying now for some hours to set the width of my TextPane. My Code is like this :

private JTextPane eingabe = new JTextPane ();
private JTextPane ausgabe = new JTextPane ();
private JScrollPane scrollbar_eingabe = new JScrollPane(eingabe);
private JScrollPane scrollbar_ausgabe = new JScrollPane(ausgabe);
......
.......

private void createLayout(JComponent... arg) {

            Container pane = this.getContentPane();
            GroupLayout layout = new GroupLayout(pane);
            pane.setLayout(layout);          

            layout.setAutoCreateContainerGaps(true);
            layout.setAutoCreateGaps(true);



            layout.setHorizontalGroup(
                    layout.createSequentialGroup() // ------
                    .addComponent(arg[0])
                    .addGroup(layout.createParallelGroup()  
                        .addComponent(arg[1])
                        .addComponent(arg[2]))                
                    .addGroup(layout.createParallelGroup()
                        .addComponent(arg[3])
                        .addComponent(arg[4]))
                   )
           ;              
            layout.setVerticalGroup(layout.createParallelGroup()        // |||||
                    .addComponent(arg[0])
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(arg[1])
                         .addComponent(arg[2]))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(arg[3])
                        .addComponent(arg[4]))
            );        

           //gl.linkSize(pwd_text, user_text ,user, pwd, start);

            pack();        
        }


    protected void initWindow() 
    {
        .....
        createLayout(start, eingabe_text, scrollbar_eingabe,script_text, scrollbar_ausgabe);
    }

The first arg is a button, the second one a label, then the first Textpane/ScrollPane, then another label and another ScrollPane. The arrangement of the components is working so far, but i realy dont get it how to set the width of one of those text/scrollpanes. The first one should have max a 1/3 of the width of the second Pane.

Everything in my program is working fine, but im just to dumb to set the width of this Scrollpane :(

Edit: It should lock like this:

A1 A2 A4
   A3 A5
And A3 should have the width A5/3.

Edit: Okay, i solved the problem with this:

Dimension d = new Dimension();

            d.height = 610;
            d.width = 250;
            arg[2].setPreferredSize(d);
            Dimension d1 = new Dimension();
            d1.height = 610;
            d1.width = d.width * 4;
            arg[4].setPreferredSize(d1);



            layout.setHorizontalGroup(
                    layout.createSequentialGroup() // ------
                    .addComponent(arg[0])
                    .addGroup(layout.createParallelGroup()  
                        .addComponent(arg[1])
                        .addComponent(arg[2], GroupLayout.PREFERRED_SIZE,
                                GroupLayout.PREFERRED_SIZE,  GroupLayout.PREFERRED_SIZE))                 
                    .addGroup(layout.createParallelGroup()
                        .addComponent(arg[3])
                        .addComponent(arg[4], GroupLayout.PREFERRED_SIZE,
                                GroupLayout.PREFERRED_SIZE,  GroupLayout.PREFERRED_SIZE))
                   )
           ;              
            layout.setVerticalGroup(layout.createParallelGroup()        // |||||
                    .addComponent(arg[0])
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(arg[1])
                        .addComponent(arg[2], GroupLayout.PREFERRED_SIZE,
                                GroupLayout.PREFERRED_SIZE,  GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(arg[3])
                        .addComponent(arg[4], GroupLayout.PREFERRED_SIZE,
                                GroupLayout.PREFERRED_SIZE,  GroupLayout.PREFERRED_SIZE))
            );        

Working with grouplayout and other layouts is realy confusing in java ;D

user3793935
  • 411
  • 5
  • 22

1 Answers1

0

If GroupLayout is not required to use, I would suggest other layout instead like GridLayout or GridBagLayout

or

JtextPane must be under different layout

niXful-Autistic
  • 217
  • 1
  • 6
  • I think i need a grouplayout, because it has to be like A1 A2 A4 A3 A5 . I dont get the layouts so far ;( You think a Gridlayout would work for this? Can i make 2 fields to one ? Edit: Shit, cante formate my text here – user3793935 Jul 23 '15 at 14:29
  • add extraJPanels then setsize() or setpreferredsize() then I would suggest .addComponent(arg[1]) to .addComponent(extraJPanel1.addComponent(arg[1)]) I have no Java Compiler currently so I wont be able to test it – niXful-Autistic Jul 23 '15 at 14:39