dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: How to add Horizontal Separator when using GroupLayout

  1. #1
    Join Date
    Feb 2018
    Posts
    3

    Question How to add Horizontal Separator when using GroupLayout

    I am currently using Java within another program called DOORS Rational Publishing Engine. I have successfully created a dialog box containing a number of questions with associated drop-downs next to each question using 2 columns within a sequentialGroup. The issue I have is that I want to separate the first 2 questions from the remaining 4 but I'm not sure how to have the separator extend through both columns. Here is the code I have thus far (keep in mind that I am not able to use native Java for this project, thus the javax.swing, etc.
    Code:
    var myFrame = javax.swing.JFrame();
    var myPanel = javax.swing.JPanel();
    var myLayout = javax.swing.GroupLayout(myPanel);
    myPanel.setLayout(myLayout);
    
    //Creates gaps between components
    myLayout.setAutoCreateGaps(true);
    
    //Creates gaps between components and window
    myLayout.setAutoCreateContainerGaps(true);
    
    //Horizontal axis component group
    var hGroup = myLayout.createSequentialGroup();
    var hComponents = myLayout.createParallelGroup();
    hComponents.addComponent(WelcomeLabel);
    hComponents.addComponent(ProjectLabel);
    hComponents.addComponent(DocumentLabel);
    hComponents.addComponent(FormalOptionLabel);
    hComponents.addComponent(SCPLabel);
    hComponents.addComponent(SCPNoteLabel);
    hComponents.addComponent(DraftLabel);
    hComponents.addComponent(AppendLabel);
    hComponents.addComponent(SignLabel);
    hGroup.addGroup(hComponents);
    
    var moreHComponents = myLayout.createParallelGroup();
    moreHComponents.addComponent(Welcome_Field);
    moreHComponents.addComponent(Project_Select_Field);
    moreHComponents.addComponent(Document_Select_Field);
    moreHComponents.addComponent(FormalOption_Field);
    moreHComponents.addComponent(SCP_Field);
    moreHComponents.addComponent(EmptyLabel);
    moreHComponents.addComponent(Draft_Field);
    moreHComponents.addComponent(Append_Field);
    moreHComponents.addComponent(Sign_Field);
    hGroup.addGroup(moreHComponents);
    
    myLayout.setHorizontalGroup(hGroup);
    
    //Vertical axis component group
    var vGroup = myLayout.createSequentialGroup();
    
    var vComponentsWelcome = myLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE);
    vComponentsWelcome.addComponent(WelcomeLabel);
    vComponentsWelcome.addComponent(Welcome_Field);
    vGroup.addGroup(vComponentsWelcome);
    
    var vComponentsProject = myLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE);
    vComponentsProject.addComponent(ProjectLabel);
    vComponentsProject.addComponent(Project_Select_Field);
    vGroup.addGroup(vComponentsProject);
    
    var vComponentsDocument = myLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE);
    vComponentsDocument.addComponent(DocumentLabel);
    vComponentsDocument.addComponent(Document_Select_Field);
    vGroup.addGroup(vComponentsDocument);
    
    //This is where I want the separator to appear spanning both columns.
    
    var vComponentsFormal = myLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE);
    vComponentsFormal.addComponent(FormalOptionLabel);
    vComponentsFormal.addComponent(FormalOption_Field);
    vGroup.addGroup(vComponentsFormal);
    
    var vComponentsSCP = myLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE);
    vComponentsSCP.addComponent(SCPLabel);
    vComponentsSCP.addComponent(SCP_Field);
    vGroup.addGroup(vComponentsSCP);
    
    var vComponentsDraft = myLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE);
    vComponentsDraft.addComponent(DraftLabel);
    vComponentsDraft.addComponent(Draft_Field);
    vGroup.addGroup(vComponentsDraft);
    
    myLayout.setVerticalGroup(vGroup);
    I suppose my first question is whether this is even possible with a groupLayout? If it is, how would I do it?

    Chris

  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,787

    Re: How to add Horizontal Separator when using GroupLayout

    Is this java or javascript? The var statement is in javascript, not java.
    Norm

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,353

    Re: How to add Horizontal Separator when using GroupLayout

    [Thread moved from Java]
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.7.6)

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    12,700

    Re: How to add Horizontal Separator when using GroupLayout

    Quote Originally Posted by ccote1 View Post
    I am currently using Java within another program called DOORS Rational Publishing Engine. I have successfully created a dialog box containing a number of questions with associated drop-downs next to each question using 2 columns within a sequentialGroup. The issue I have is that I want to separate the first 2 questions from the remaining 4 but I'm not sure how to have the separator extend through both columns. Here is the code I have thus far (keep in mind that I am not able to use native Java for this project, thus the javax.swing, etc.
    Code:
    var myFrame = javax.swing.JFrame();
    var myPanel = javax.swing.JPanel();
    var myLayout = javax.swing.GroupLayout(myPanel);
    myPanel.setLayout(myLayout);
    
    //Creates gaps between components
    myLayout.setAutoCreateGaps(true);
    
    //Creates gaps between components and window
    myLayout.setAutoCreateContainerGaps(true);
    
    //Horizontal axis component group
    var hGroup = myLayout.createSequentialGroup();
    var hComponents = myLayout.createParallelGroup();
    hComponents.addComponent(WelcomeLabel);
    hComponents.addComponent(ProjectLabel);
    hComponents.addComponent(DocumentLabel);
    hComponents.addComponent(FormalOptionLabel);
    hComponents.addComponent(SCPLabel);
    hComponents.addComponent(SCPNoteLabel);
    hComponents.addComponent(DraftLabel);
    hComponents.addComponent(AppendLabel);
    hComponents.addComponent(SignLabel);
    hGroup.addGroup(hComponents);
    
    var moreHComponents = myLayout.createParallelGroup();
    moreHComponents.addComponent(Welcome_Field);
    moreHComponents.addComponent(Project_Select_Field);
    moreHComponents.addComponent(Document_Select_Field);
    moreHComponents.addComponent(FormalOption_Field);
    moreHComponents.addComponent(SCP_Field);
    moreHComponents.addComponent(EmptyLabel);
    moreHComponents.addComponent(Draft_Field);
    moreHComponents.addComponent(Append_Field);
    moreHComponents.addComponent(Sign_Field);
    hGroup.addGroup(moreHComponents);
    
    myLayout.setHorizontalGroup(hGroup);
    
    //Vertical axis component group
    var vGroup = myLayout.createSequentialGroup();
    
    var vComponentsWelcome = myLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE);
    vComponentsWelcome.addComponent(WelcomeLabel);
    vComponentsWelcome.addComponent(Welcome_Field);
    vGroup.addGroup(vComponentsWelcome);
    
    var vComponentsProject = myLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE);
    vComponentsProject.addComponent(ProjectLabel);
    vComponentsProject.addComponent(Project_Select_Field);
    vGroup.addGroup(vComponentsProject);
    
    var vComponentsDocument = myLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE);
    vComponentsDocument.addComponent(DocumentLabel);
    vComponentsDocument.addComponent(Document_Select_Field);
    vGroup.addGroup(vComponentsDocument);
    
    //This is where I want the separator to appear spanning both columns.
    
    var vComponentsFormal = myLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE);
    vComponentsFormal.addComponent(FormalOptionLabel);
    vComponentsFormal.addComponent(FormalOption_Field);
    vGroup.addGroup(vComponentsFormal);
    
    var vComponentsSCP = myLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE);
    vComponentsSCP.addComponent(SCPLabel);
    vComponentsSCP.addComponent(SCP_Field);
    vGroup.addGroup(vComponentsSCP);
    
    var vComponentsDraft = myLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE);
    vComponentsDraft.addComponent(DraftLabel);
    vComponentsDraft.addComponent(Draft_Field);
    vGroup.addGroup(vComponentsDraft);
    
    myLayout.setVerticalGroup(vGroup);
    I suppose my first question is whether this is even possible with a groupLayout? If it is, how would I do it?

    Chris
    Not a java(script) swing expert, but try searching for "javax.swing horizontal divider". There seems to be several code snippets, and while perhaps grouplayout may not work, there should be other containers that will.

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    12,700

    Re: How to add Horizontal Separator when using GroupLayout

    Quote Originally Posted by Norm View Post
    Is this java or javascript? The var statement is in javascript, not java.
    Seems like var could be on its way to java. http://openjdk.java.net/jeps/286. My experience is it takes a while to get used to over explicit variable type declarations, but ends up making the code easier to read and still type safe.

  6. #6
    Join Date
    Feb 2018
    Posts
    3

    Re: How to add Horizontal Separator when using GroupLayout

    As I should have mentioned in my original post, I'm actually using what I would call quasi-java within DOORS RPE. I apologize for not being clear about that. While DOORS uses Javascript, I'm still, somehow, able to use java functionality to create dialog boxes. I have now figured out how to add the separator, but because of the setAutoCreateGaps, I have 2 individual lines with a gap between them. I'm not sure if it's possible to remove the space between the columns in a single row in the vertical axis group of a Java GroupLayout.
    Code:
    //Creates gaps between components
    myLayout.setAutoCreateGaps(true);
    
    ... 
    ... Add Horizontal axis groups for GroupLayout
    ...
    
    var vComponentsDocument = myLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE);
    vComponentsDocument.addComponent(DocumentLabel);
    vComponentsDocument.addComponent(Document_Select_Field);
    vGroup.addGroup(vComponentsDocument);
    
    //I'd like to, if possible, remove the gap between the 2 separators in this row
    var vComponentsSeparators = myLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE);
    vComponentsSeparators.addComponent(hSeparator1);
    vComponentsSeparators.addComponent(hSeparator2);
    vGroup.addGroup(vComponentsSeparators);
    
    var vComponentsFormal = myLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE);
    vComponentsFormal.addComponent(FormalOptionLabel);
    vComponentsFormal.addComponent(FormalOption_Field);
    vGroup.addGroup(vComponentsFormal);

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




On-Demand Webinars (sponsored)