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
If GroupLayout is not required to use, I would suggest other layout instead like GridLayout or GridBagLayout
or
JtextPane must be under different layout
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.