Solved

Java Swing : Alignment Customization

Posted on 2006-11-26
13
431 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

617 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