aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Problem when adding a new JTextPane to GroupLayout at run time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem when adding a new JTextPane to GroupLayout at run time" Watch "Problem when adding a new JTextPane to GroupLayout at run time" New topic

Problem when adding a new JTextPane to GroupLayout at run time

pn goel

Joined: Dec 07, 2009
Posts: 2

I am new to Java. I am Creating a Editor Application in Java. Initally this applcation has a JTextPane(name EditorPane) which occupies all of the sapce of JInternalFrame and My maintoolbar also has a button to add the new JTextPane(name headPane) to the JInternalFrame Form at runtime. In the Editor class which extends JInternalFrame class , I am using the following code to add the JTextPane (at initial stage):

JTextPane HeadPane, EditorPane;
GroupLayout layout;
GroupLayout.SequentialGroup hseqgroup;
GroupLayout.SequentialGroup vseqgroup;

Editor() // Constructor of my JInternalFrame class
setPreferredSize(new java.awt.Dimension(800, 600));
EditorPane = new javax.swing.JTextPane();
EditorPane.setMaximumSize(new Dimension(2147483647,2147483647));
EditorPane.setMinimumSize(new Dimension(6,21));
EditorPane.setPreferredSize(new Dimension(6,21));

layout = new javax.swing.GroupLayout(getContentPane());

hseqgroup = layout.createSequentialGroup();
vseqgroup = layout.createSequentialGroup();
GroupLayout.ParallelGroup hParallelGroup1 = layout.createParallelGroup
hParallelGroup1.addComponent(EditorPane, javax.swing.GroupLayout.DEFAULT_SIZE, 790,


GroupLayout.ParallelGroup vparallelGroup1 = layout.createParallelGroup(GroupLayout.Alignment.LEADING);
vparallelGroup1.addComponent(EditorPane, javax.swing.GroupLayout.Alignment.TRAILING,
540, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE);

this.closable = true;
this.maximizable = true;

and in the addNewJTextPane Button, I am using the following code:

HeadPane = new JTextPane();
HeadPane.setBounds(0, 0, EditorPane.getWidth(), 100);

HeadPane.setMaximumSize(new Dimension(2147483647,100));

GroupLayout.ParallelGroup hparallelGroup1 = layout.createParallelGroup
hparallelGroup1.addComponent(HeadPane, GroupLayout.DEFAULT_SIZE, 790, Short.MAX_VALUE);


GroupLayout.ParallelGroup vparallelGroup1 = layout.createParallelGroup (GroupLayout.Alignment.LEADING);
vparallelGroup1.addComponent(HeadPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE);


this.EditorPane.setLocation(0, 120);

When the user clicked on the button to add the new JTextPane, it adds the New JTextPane to the JInternal Form But change the size of the previous JTextPane and also the new JTextPane size and location not correct.

The form is appearing like it has devided into two columns and the first column displays the previous JTextPane and the second column displays the new JTextPane starting from the last of the First JTextPane.

I want to add the New JtextPane to the top of the previous JTextPane and also both JTextPane should occupy the complete horizontal area of the form. Only their vertical size should be differ and they should also resize when the form resize. Also I want to fix the vertical size of the new JTextPane not of the previous JTextPane.

How can I do it?
K. Tsang

Joined: Sep 13, 2007
Posts: 2615

Welcome to the Ranch. Please use code tags when posting codes.

You are using a GroupLayout. Have you try using other layout managers to see how it will look? For swing, choosing a proper layout manager is key.

I think fiddle around with different layout managers like flow, border, grid etc to see the effect. Also you can have several "panels" in each section and even panel can have its own layout manager. So it's endless possibilities lol.

I agree. Here's the link:
subject: Problem when adding a new JTextPane to GroupLayout at run time