[RESOLVED] Problem when adding a new JTextPane to GroupLayout at runtime
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: [RESOLVED] Problem when adding a new JTextPane to GroupLayout at runtime

  1. #1
    Join Date
    Dec 2009
    Posts
    5

    [RESOLVED] Problem when adding a new JTextPane to GroupLayout at runtime

    Hi,

    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
    {
    setOpaque(true);
    setPreferredSize(new java.awt.Dimension(800, 600));
    EditorPane = new javax.swing.JTextPane();
    EditorPane.setOpaque(true);
    EditorPane.setMaximumSize(new Dimension(2147483647,2147483647));
    EditorPane.setMinimumSize(new Dimension(6,21));
    EditorPane.setPreferredSize(new Dimension(6,21));

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

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

    hseqgroup.addGroup(hParallelGroup1);

    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);

    vseqgroup.addGroup(vparallelGroup1);
    layout.setHorizontalGroup(hseqgroup);
    layout.setVerticalGroup(vseqgroup);
    pack();
    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.setOpaque(true);
    HeadPane.setMaximumSize(new Dimension(2147483647,100));
    HeadPane.setMinimumSize(EditorPane.getMinimumSize());
    HeadPane.setPreferredSize(EditorPane.getPreferredSize());

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

    hseqgroup.addGroup(hparallelGroup1);

    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);

    vseqgroup.addGroup(vparallelGroup1);

    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?

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,474

    Re: Problem when adding a new JTextPane to GroupLayout at runtime

    Please do not start a new thread when asking for further help, if you start a new thread then we lose the history of the problem and could end up duplicating answers given in the original thread.

    Please add all answers to this thread

  3. #3
    Join Date
    Dec 2009
    Posts
    5

    Smile Re: Problem when adding a new JTextPane to GroupLayout at runtime

    I have solved this. I have changed the GroupLayout with GridBoxLayout and it is working what I want.

    Thanks to all.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center