简体   繁体   English

如何在GroupLayout中设置JTextPane的宽度?

[英]How do i set the width of an JTextPane in a GroupLayout?

im trying now for some hours to set the width of my TextPane. 我现在尝试了几个小时来设置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) { 私人无效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. 第一个arg是一个按钮,第二个是一个标签,然后是第一个Textpane / ScrollPane,然后是另一个标签和另一个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. 第一个窗格的最大宽度应为第二个窗格的1/3。

Everything in my program is working fine, but im just to dumb to set the width of this Scrollpane :( 我程序中的所有内容都可以正常工作,但是我只是笨拙地设置了此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 = 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 在Java中,使用grouplayout和其他布局确实令人困惑; D

If GroupLayout is not required to use, I would suggest other layout instead like GridLayout or GridBagLayout 如果不需要使用GroupLayout,我建议使用其他布局,例如GridLayout或GridBagLayout

or 要么

JtextPane must be under different layout JtextPane必须使用不同的布局

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM