Results 1 to 6 of 6

Thread: How to use SpringLayout in Java?

  1. #1
    Join Date
    Aug 2006
    Posts
    162

    How to use SpringLayout in Java?

    Hi friends,
    I have used many types of the layout managers in Java. I have used Border Layout, Grid Layout, etc. but never heard about the Spring Layout. So thought that instead of searching on Web, it will be better to post here. So explain me what is the Spring Layout. Also please explain me how to use Spring Layout in Java.?? Please help me as soon as possible.
    Processor: AMD Athlon(tm) 64 X2 Dual Core @ ~2.2 GHz
    Memory: 1024MB RAM
    Hard Drive: 200 GB
    Video Card: RADEON X300/X550 Series

  2. #2
    Join Date
    Mar 2008
    Posts
    672

    Re: How to use SpringLayout in Java?

    Spring Layout are not frequently used, that's why you may be not heard about that.!! According to a set of constraints, a spring layout lays out the children of its associated container. But one big advantage of using that is SpringLayout is a very flexible layout manager that can emulate many of the features of other layout managers. You can also consider SpringLayout as very low-level and you will have to use it with a GUI builder. Its always better to use it with a GUI builder rather than attempting to code a spring layout manager by hand.

  3. #3
    Join Date
    Mar 2008
    Posts
    349

    Re: How to use SpringLayout in Java?

    Before going for the coding, you should know about the spring layout and the method of it working. So I have provided you with an useful information that may help you a lot. The tasks that are done by the Spring layouts by defining directional relationships, or constraints, between the edges of components. Just take an example so that you can understand it more properly. You might define that the right edge of one component is a fixed distance, say 10 pixels, from the left edge of another component. The position of each edge is dependent on the position of just one other edge, in a a SpringLayout.

  4. #4
    Join Date
    Jul 2006
    Posts
    289

    Re: How to use SpringLayout in Java?

    You must also know about the Constructor or Method before using that in the coding. The following are the Constructor or Method of SpringLayout :
    • SpringLayout() - This method create a SpringLayout instance.
    • SpringLayout.Constraints getConstraints(Component) - By using this method you can get the constraints associated with the specified component.
    • Spring getConstraint(String, Component) - By using this method you can get the spring for an edge of a component.
    • void putConstraint(String, Component, int, String, Component) - This is a Convenience methods for defining relationships between the edges of two components.
    Signatures reduce available bandwidth

  5. #5
    Join Date
    Nov 2008
    Posts
    996

    Re: How to use SpringLayout in Java?

    I think that you should have understood little bit of the concepts. After having a look on the coding, I think that it will be easy for you to understand. So I have provided you with the coding that features a label and a text field in a content pane controlled by a spring layout. The following coding explains the same :
    Code:
    public class SpringTrial {
        public static void main(String[] args) {
            ...
            Container contentPane = frame.getContentPane();
            SpringLayout layout = new SpringLayout();
            contentPane.setLayout(layout);
            contentPane.add(new JLabel("Label: "));
            contentPane.add(new JTextField("Text field", 25));
            ...
            frame.pack();
            frame.setVisible(true);
        }
    }

  6. #6
    Join Date
    Jul 2006
    Posts
    286

    Re: How to use SpringLayout in Java?

    You may also would use SpringGrid in the SpringLayout. The following is the code that creates and lays out the text fields in SpringGrid :
    Code:
    JPanel pan = new JPanel(new SpringLayout());
    for (int i = 0; i < 12; i++) {
        JTextField textField = new JTextField(Integer.toString(i));
        pan.add(textField);
    }
    ...
    SpringUtilities.makeGrid(pan,
                             4, 4, 
                             6, 6, 
                             6, 6);
    IF you hate me, please don't mention it. I know who hates me and who doesn't. You really do not have to make fun of people....

Similar Threads

  1. Replies: 4
    Last Post: 04-09-2013, 11:04 PM
  2. Setting Of Java to The Point At Manual Java
    By winni in forum Software Development
    Replies: 4
    Last Post: 10-01-2011, 10:05 PM
  3. SpringLayout.Constraints class
    By Prashobh Mallu in forum Software Development
    Replies: 5
    Last Post: 11-02-2010, 09:35 AM
  4. Link List Example in Java Sample program in Java
    By trickson in forum Software Development
    Replies: 2
    Last Post: 04-08-2009, 08:23 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,671,211.06548 seconds with 17 queries