Solved

Java Swing : Alignment Customization

Posted on 2006-11-26
13
429 Views
Last Modified: 2013-11-23
Dear experts:

Hi again!

I have a small, nice-working Java applet code.

I would like to make some changes to its layout or alignment in such a way that "rankList" combo box is vertically aligned with "Rnaks" sub-heading with some space from the left margin and more buffer space is placed between topPanel and centerPanel and between centerPanel and bottomPanel like as below:


________________________  My wished Costumized Layout _________________________________
 
                                            Payroll Calculator

                                            (More space between Payroll Calculator and the subheadings below)

         Ranks                                    Marriage Status                         Residency Status
        ComboBox                             @ Married                                 @ Resident
                                                    @ Single                                   @ Nonresident


<--->  an inch from the left margin
                                                   ______________________
      Years in Current Position:       |_____________________|
                                             (more space between "years in current position" and "Hours worked this month"
                                                  ______________________
      Hours   Worked This Month:   |_____________________|
                                            (more space between the above and the below )
                                                    ______________________
      Your Total Pay This Month:       |_____________________|

                                             (more space  between the above and the below )
                                             ___________                     ______________
                                            | Calculate   |                    |  Reset             |
                                            |__________|                   |_____________|
                             

________________________________________________________________________________

I would like to learn how to customize from you experts.

Thanks a lot!

duta



0
Comment
Question by:duta
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
13 Comments
 
LVL 14

Accepted Solution

by:
hoomanv earned 500 total points
ID: 18015370
I suggest you use TableLayout: https://tablelayout.dev.java.net/
IMHO its the best layout manager I've ever seen, just read its tutorial to get start
0
 

Author Comment

by:duta
ID: 18015396
Thanks a lot, hoomanv.

I am checking the site you kindly gave me. I will be back after trying it.

Thanks again!

duta
0
 

Author Comment

by:duta
ID: 18015432
TO: hoomanv:

I downloaded four  .jar files, and do not know what do with them.
There are no directions available regarding the four files.

Do I need to place them in a folder in the directory of  jdk 1.5 or jre 1.5? Do I need to register to use them?

Thanks a lot!

duta
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 14

Expert Comment

by:hoomanv
ID: 18015438
TableLayout.jar should be included in your classpath
0
 

Author Comment

by:duta
ID: 18015457
Thanks again, hoomanv.

In C:\Program Files\Java\jre1.5.0_07\lib, I found several .jar files.  Do you mean "C:\Program Files\Java\jre1.5.0_07\lib" as the classpath?

duta
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 18015484
mindprod.com/jgloss/classpath.html
CLASSPATH is an environment variable
You can set/view it through the command line
type
> set classpath
to view it
and to add new paths to it type
> set classpath=%classpath%;new-path
the new-path in your case is the absolute path to TableLayout.jar
for example:
> set classpath=%classpath%;c:\TableLayout.jar
now you successfully installed this library
read the tutorial to learn how to this layout manager works
https://tablelayout.dev.java.net/articles/TableLayoutTutorialPart1/TableLayoutTutorialPart1.html
0
 

Author Comment

by:duta
ID: 18015511
To: hoomanv:
Thanks a lot for your kind tips.

By the way, I wonder whether I may ask you one more quick question:

I put "TableLayout.jar" in the directory of  "c:\Program Files\Java\tableLayout".

Do I need to go to run > type "set classpath = %classpath%; c:\Program Files\Java\tableLayout\TableLayout.jar"?

Thanks

duta

0
 
LVL 14

Expert Comment

by:hoomanv
ID: 18015534
If you put it in C:\Program Files\Java\jre*****\lib\ext
Then there is no need to set classpath
0
 

Author Comment

by:duta
ID: 18015546
hoomanv, thanks a lot for your kind, patient tips.

I will take time to read all the instructions in the site.

Thanks again!
0
 

Author Comment

by:duta
ID: 18050024
TO: hoomanv:

Thanks for your kind help.

By the way, when trying to compile, I got an error message:

ERROR: Package layout does not exist.

___________ Here are my imports _______________
import  java.awt.*;
import  javax.swing.*;
import  java.awt.event.*;
import  layout.TableLayout;
_______________________________________________
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 18051706
This one is correct
import info.clearthought.layout.TableLayout;
0
 

Author Comment

by:duta
ID: 18064950
TO: hoomanv:

Hi again!

I found a simple TableLayout tutorial at a website, and tried the sample code (below). I got an error message:

"canot find symbol constructor TableLayout".

Can you kindly find why?  I am trying the code because it looked really  simple.

Thanks!

_________________________  Sample code _____________


import  java.awt.*;
import  javax.swing.*;
import  java.awt.event.*;
import info.clearthought.layout.TableLayout;




public class Example1
{


public static void
main(
    String[] args)
{
    new Example1();
}


public
Example1()
{
    JFrame frame1 = createGridBagLayout();
    JFrame frame2 = createTableLayout();
    frame1.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame2.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame1.pack();
    frame2.pack();
    frame1.setLocation(10, 100);
    frame2.setLocation(400, 100);
    frame1.setVisible(true);
    frame2.setVisible(true);
}

//**********************************************************************
// Private
//**********************************************************************

/**
 * Create the layout using GridBagLayout. This code comes from the API
 * page for GridBagLayout.
 *
 * @return The JFrame containing the layout.
 */

public JFrame
createGridBagLayout()
{
    JFrame frame = new JFrame("GridBagLayout");

    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();

    JPanel panel = new JPanel(gridbag);
    frame.getContentPane().add(panel);

    c.fill = GridBagConstraints.BOTH;
    c.weightx = 1.0;
    makebutton(panel, "Button1", gridbag, c);
    makebutton(panel, "Button2", gridbag, c);
    makebutton(panel, "Button3", gridbag, c);

    c.gridwidth = GridBagConstraints.REMAINDER; //end row
    makebutton(panel, "Button4", gridbag, c);

    c.weightx = 0.0;   //reset to the default
    makebutton(panel, "Button5", gridbag, c); //another row

    c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last in row
    makebutton(panel, "Button6", gridbag, c);

    c.gridwidth = GridBagConstraints.REMAINDER; //end row
    makebutton(panel, "Button7", gridbag, c);

    c.gridwidth = 1;   //reset to the default
    c.gridheight = 2;
    c.weighty = 1.0;
    makebutton(panel, "Button8", gridbag, c);

    c.weighty = 0.0;   //reset to the default
    c.gridwidth = GridBagConstraints.REMAINDER; //end row
    c.gridheight = 1;   //reset to the default
    makebutton(panel, "Button9", gridbag, c);
    makebutton(panel, "Button10", gridbag, c);

    return frame;
}

/**
 * Helper method for createGridBagLayout().
 *
 * @param panel The panel to add the button to.
 * @param name The button's label.
 * @param gridbag The GridBagLayout to use.
 * @param c The constraints to use.
 */

private void
makebutton(
    JPanel panel,
    String name,
    GridBagLayout gridbag,
    GridBagConstraints c)
{
    JButton button = new JButton(name);
    gridbag.setConstraints(button, c);
    panel.add(button);
}

/**
 * Create the layout using TableLayout.
 *
 * @return The JFrame containing the layout.
 */

public JFrame
createTableLayout()
{
    JFrame frame = new JFrame("TableLayout");

    JPanel panel = new JPanel(new TableLayout("cols=4"));
    frame.getContentPane().add(panel);

    panel.add(new JButton("Button1"));
    panel.add(new JButton("Button2"));
    panel.add(new JButton("Button3"));
    panel.add(new JButton("Button4"));
    panel.add(new JButton("Button5"), "cspan=4");
    panel.add(new JButton("Button6"), "cspan=3");
    panel.add(new JButton("Button7"));
    panel.add(new JButton("Button8"), "rspan=2");
    panel.add(new JButton("Button9"), "cspan=3");
    panel.add(new JButton("Button10"), "cspan=3 rweight=1");

    return frame;
}

}
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 18066524
These are the constructors

TableLayout()
TableLayout(double[][] size)
TableLayout(double[] col, double[] row)

There is no TableLayout(String s) !!! thats why you get error

Read the tutorial https://tablelayout.dev.java.net/articles/TableLayoutTutorialPart1/TableLayoutTutorialPart1.html
Everything is explained there
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Facing this issue for maven proxy setting 2 45
hashmap order 17 63
Html split(text) 2 49
Selenium findElement(By.classname  identifier 15 35
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question