GetLocation in a SpringLayout

Okay, this has got me totally confused. My program works just fine (I'm not going to post code because the Swing components are built up dynamically from model-view data), except that getLocation and getX/getY don't report the proper location.
I have a Label inside a Panel. It's a SpringLayout and the Label has top/left springs to the top/left edges of the panel, and displays exactly where I want it. However, the position of the label is ALWAYS reported as (5,21), which is the upper-left pixel inside the panel's insets (it has a border with a text label). Like I said, the label displays fine, I can set it to anywhere in the panel and it goes there, I query the location well after it's onscreen and periodically through the program, and it's always "at" (5,21). ???
Here's what I'm trying to do, and if this is answerable and the above is not, I'll be just as happy: Since Panel doesn't have pack(), I'm trying to make it increase in size if any item in the built-up SpringLayout tree of components exceeds the current size of the panel. Is there some auto-flowing, 'preferredSize' way of doing this instead?

BTW, I also tried label.getLocationOnScreen and subtracting it from the region's getLocationOnScreen, and it also came to (5,21).

Similar Messages

  • SpringLayout?

    Hi
    I have just started lerning Java in my school, but they are only doing Applets and whith no LayoutManagers. But I want to learn more. My teacher isn't very good at this so I'm asking you. If you can tell me what is wrong with this code.
    The program dosen't do anything yet so thats not the problem. I'm having problem with the SpringLayout.
    Here is the code.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.Container;
    import java.awt.event.*;
    public class SpringDemo1 implements ActionListener{
         * Create the GUI and show it.  For thread safety,
         * this method should be invoked from the
         * event-dispatching thread.
         Container contentPane;
        public void createAndShowGUI() {
            //Create and set up the window.
            JFrame frame = new JFrame("Sl�ttar T�lur");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              contentPane = frame.getContentPane();
              prentaVidmot();
              //takki.addActionListener(this);
            //S�na gluggan
            frame.pack();
            frame.setVisible(true);
         public static void prentaVidmot(){
               //Set up the content pane.
              //SpringLayout layout = new SpringLayout();
              JPanel kassi = new JPanel();
              SpringLayout layout = new SpringLayout();
              kassi.setLayout(layout);
              kassi.setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
              //Create and add the components.
              JLabel label = new JLabel("Tala: ");
              JTextField tala = new JTextField(15);
              JLabel labelNidurstodur = new JLabel("Ni�urst��ur: ");
              TextArea textabox = new TextArea(5,21);
              JButton takki = new JButton("Reikna");
              kassi.add(label);
              kassi.add(tala);
              kassi.add(labelNidurstodur);
              kassi.add(textabox);
              kassi.add(takki);
              //Stilla sta�setningu label
              kassi.putConstraint(SpringLayout.WEST, label, 5,SpringLayout.WEST, kassi);
              kassi.putConstraint(SpringLayout.NORTH, label,5,SpringLayout.NORTH, kassi);
              //Stilla sta�setningu tala
              kassi.putConstraint(SpringLayout.WEST, tala,50,SpringLayout.EAST, label);
              kassi.putConstraint(SpringLayout.NORTH, tala,5,SpringLayout.NORTH, kassi);
              //Stilla sta�setningu labelNidurstodur
              kassi.putConstraint(SpringLayout.WEST, labelNidurstodur, 0, SpringLayout.WEST, label);
              kassi.putConstraint(SpringLayout.NORTH, labelNidurstodur, 10, SpringLayout.SOUTH, label);
              //Stilla sta�setningu textabox
              kassi.putConstraint(SpringLayout.WEST, textabox, 0, SpringLayout.WEST, tala);
              kassi.putConstraint(SpringLayout.NORTH, textabox, 5, SpringLayout.SOUTH, tala);
              //Stilla sta�setningu takka
              kassi.putConstraint(SpringLayout.EAST, takki,0,SpringLayout.EAST, textabox);
              kassi.putConstraint(SpringLayout.NORTH, takki,10,SpringLayout.SOUTH, textabox);
              //Stilla st�r� glugga
         public void actionPerformed(ActionEvent event){
              double teljari = (Double.parseDouble(tala.getText()));
              System.out.println("Foo");
        public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
    }And here is the error:
    N:\T�l103\Forritun\javasafn\forrit_04_01\SpringDemo1.java:66: cannot resolve symbol
    symbol : method putConstraint (java.lang.String,javax.swing.JLabel,int,java.lang.String,javax.swing.JPanel)
    location: class javax.swing.JPanel
              kassi.putConstraint(SpringLayout.WEST, label, 5,SpringLayout.WEST, kassi);
    ^
    N:\T�l103\Forritun\javasafn\forrit_04_01\SpringDemo1.java:67: cannot resolve symbol
    symbol : method putConstraint (java.lang.String,javax.swing.JLabel,int,java.lang.String,javax.swing.JPanel)
    location: class javax.swing.JPanel
              kassi.putConstraint(SpringLayout.NORTH, label,5,SpringLayout.NORTH, kassi);
    ^
    N:\T�l103\Forritun\javasafn\forrit_04_01\SpringDemo1.java:70: cannot resolve symbol
    symbol : method putConstraint (java.lang.String,javax.swing.JTextField,int,java.lang.String,javax.swing.JLabel)
    location: class javax.swing.JPanel
              kassi.putConstraint(SpringLayout.WEST, tala,50,SpringLayout.EAST, label);
    ^
    N:\T�l103\Forritun\javasafn\forrit_04_01\SpringDemo1.java:71: cannot resolve symbol
    symbol : method putConstraint (java.lang.String,javax.swing.JTextField,int,java.lang.String,javax.swing.JPanel)
    location: class javax.swing.JPanel
              kassi.putConstraint(SpringLayout.NORTH, tala,5,SpringLayout.NORTH, kassi);
    ^
    N:\T�l103\Forritun\javasafn\forrit_04_01\SpringDemo1.java:74: cannot resolve symbol
    symbol : method putConstraint (java.lang.String,javax.swing.JLabel,int,java.lang.String,javax.swing.JLabel)
    location: class javax.swing.JPanel
              kassi.putConstraint(SpringLayout.WEST, labelNidurstodur, 0, SpringLayout.WEST, label);
    ^
    N:\T�l103\Forritun\javasafn\forrit_04_01\SpringDemo1.java:75: cannot resolve symbol
    symbol : method putConstraint (java.lang.String,javax.swing.JLabel,int,java.lang.String,javax.swing.JLabel)
    location: class javax.swing.JPanel
              kassi.putConstraint(SpringLayout.NORTH, labelNidurstodur, 10, SpringLayout.SOUTH, label);
    ^
    N:\T�l103\Forritun\javasafn\forrit_04_01\SpringDemo1.java:78: cannot resolve symbol
    symbol : method putConstraint (java.lang.String,java.awt.TextArea,int,java.lang.String,javax.swing.JTextField)
    location: class javax.swing.JPanel
              kassi.putConstraint(SpringLayout.WEST, textabox, 0, SpringLayout.WEST, tala);
    ^
    N:\T�l103\Forritun\javasafn\forrit_04_01\SpringDemo1.java:79: cannot resolve symbol
    symbol : method putConstraint (java.lang.String,java.awt.TextArea,int,java.lang.String,javax.swing.JTextField)
    location: class javax.swing.JPanel
              kassi.putConstraint(SpringLayout.NORTH, textabox, 5, SpringLayout.SOUTH, tala);
    ^
    N:\T�l103\Forritun\javasafn\forrit_04_01\SpringDemo1.java:82: cannot resolve symbol
    symbol : method putConstraint (java.lang.String,javax.swing.JButton,int,java.lang.String,java.awt.TextArea)
    location: class javax.swing.JPanel
              kassi.putConstraint(SpringLayout.EAST, takki,0,SpringLayout.EAST, textabox);
    ^
    N:\T�l103\Forritun\javasafn\forrit_04_01\SpringDemo1.java:83: cannot resolve symbol
    symbol : method putConstraint (java.lang.String,javax.swing.JButton,int,java.lang.String,java.awt.TextArea)
    location: class javax.swing.JPanel
              kassi.putConstraint(SpringLayout.NORTH, takki,10,SpringLayout.SOUTH, textabox);
    ^
    N:\T�l103\Forritun\javasafn\forrit_04_01\SpringDemo1.java:90: cannot resolve symbol
    symbol : variable tala
    location: class SpringDemo1
              double teljari = (Double.parseDouble(tala.getText()));
    ^
    N:\T�l103\Forritun\javasafn\forrit_04_01\SpringDemo1.java:101: non-static method createAndShowGUI() cannot be referenced from a static context
    createAndShowGUI();
    ^
    12 errors
    Tool completed with exit code 1

    If you are just learning Java, you should not start with GUI programming. You'll need all the basics to really understand what you are doing.
    For example you seem to have problems reading and understanding error messages. That's understandable, because at first they may seem intimidating.
    Let's look at the first error:
    N:\T�l103\Forritun\javasafn\forrit_04_01\SpringDemo1.java:66: cannot resolve symbol
    symbol : method putConstraint (java.lang.String,javax.swing.JLabel,int,java.lang.String,javax.swing.JPanel)
    location: class javax.swing.JPanel
    kassi.putConstraint(SpringLayout.WEST, label, 5,SpringLayout.WEST, kassi);
    ^The first line tells you where the problem occurs (the file and the line nummer) and what the general error is ("cannot resolve symbol" means that some class/method/variable/... can't be found).
    The second line tells you which symbol it can't find (a method named putConstraint taking the list of parameters specified).
    The third line tells you where it tried to find the symbol (the class JPanel).
    The fourth line shows you the line of code that didn't compile.
    You should now analyze and fix each error one, one after the other.

  • How to center components horizontally in container with SpringLayout layout

    Hello,
    I've got a button and a text field in container with SpringLayout layout set. How can I center text field horizontally (buttong is the highest component)?
    I don't want use hacks like settings all heights manually.
    With regards,
    Pavel Krupets

    Sorry vertically!!!

  • Logging & Tracing - Location.getLocation(????????????????)

    Hi!
    I have a java File *.java  which is inside of Developments
    src/packages/.......
    The problem is now that I would like trace some methods and variables of this class(*.java ).
    But I can't use - >  wdThis.wdGetIPersonController().getLocation() in the mentioned java File.
    What can I use instead of ?
    mLocation =
         Location.getLocation(????????????????)
    The standard usage of Logging at WebDynpro  is as follows:
    I have to implement a getLocation method:
      public com.sap.tc.logging.Location getLocation( )
        //@@begin getLocation()
    mLocation =
         Location.getLocation(                         wdThis.wdGetIPersonController().getLocation(),
         "im.IPersonMainView");
         return getLocation();
              return mLocation;
        //@@end

    Sas-
    You do not have to create a getLocation() method. When you create a component/view/custom controllers. Each controller has a private Location reference:
      private static final com.sap.tc.logging.Location logger =
        com.sap.tc.logging.Location.getLocation(TableCompView.class);
    Just use this reference logger for all your logging needs. For example:
    logger.debugT("The number of rows fetched is " + numRows);
    Cheers-
    Atul

  • SpringLayout Unexpected Behavior: Up, Up, and Away!

    Hoping to replace several custom layout managers, I have been tinkering with SpringLayout. Odd things are going on. When I increase the parent's height, some components move out of sight. To see a similar effect:
    (1) get SpringDemo3.java from How to Use SpringLayout. http://java.sun.com/docs/books/tutorial/uiswing/layout/example-1dot4/SpringDemo3.java
    (2) change one line of code to replace the JTextArea with a JButton or a JLabel
    //JTextField textField = new JTextField("Text field", 15);
    JLabel textField = new JLabel("Not Text Field");(3) Run the revised SpringDemo3
    (4) Increase the frame's height (with the mouse, not in code)
    (5) The first label moves up and disappears out the top of the frame!

    A very interesting problem, with a very simple solution after a very large amount of messing around. Luckily for both of us I ran into a similar problem yesterday with my reply on this thread While fixing that I found your solution.
    Just add this constraint to your modified SpringDemo3 and it ties your columns together and they don't float any more.
    layout.putConstraint(SpringLayout.SOUTH, label, 0, SpringLayout.SOUTH, textField);You can tie either the north or the south together to tie stop the floating.

  • GUI's - SpringLayout

    I am attempting to create a GUI which takes from user Last Name, First Name, Middle Initial, etc. How can I set the JLabels to be aligned (which I already have) and text fields aligned but different sizes? Here is my code and I am trying to make the Middle Initial TextField shorter than the others but still aligned to the left under the other fields.
    Any help is appreciated...
    public class SpringForm2
    * Create the GUI and show it. For thread safety,
    * this method should be invoked from the
    * event-dispatching thread.
    private static void createAndShowGUI()
    String[] labels = {"Last Name: ", "First Name: ", "Middle Initial: ",
    "Facility: ", "Seniority Date: ", "Score: ", "Scramble: " };
    System.out.println(labels.length);
    int numPairs = labels.length;
    int textFieldLength = 0;
    //Create and populate the panel.
    JPanel p = new JPanel(new SpringLayout());
    //for (int i = 0; i < numPairs; i++)
    JLabel LNameLabel = new JLabel(labels[0], JLabel.TRAILING);
    p.add(LNameLabel);
    JTextField LNameField = new JTextField(10);
    LNameLabel.setLabelFor(LNameField);
    p.add(LNameField);
    JLabel FNameLabel = new JLabel(labels[1], JLabel.TRAILING);
    p.add(FNameLabel);
    JTextField FNameField = new JTextField(10);
    FNameLabel.setLabelFor(FNameField);
    p.add(FNameField);
    JLabel MNameLabel = new JLabel(labels[2], JLabel.TRAILING);
    p.add(MNameLabel);
    JTextField MNameField = new JTextField(5);
    MNameField.setMaximumSize(new Dimension(2, 5));
    MNameLabel.setLabelFor(MNameField);
    p.add(MNameField);
    JLabel FacilityLabel = new JLabel(labels[3], JLabel.TRAILING);
    p.add(FacilityLabel);
    JTextField FacilityField = new JTextField(10);
    FacilityLabel.setLabelFor(FacilityField);
    p.add(FacilityField);
    JLabel SenDateLabel = new JLabel(labels[4], JLabel.TRAILING);
    p.add(SenDateLabel);
    JTextField SenDateField = new JTextField(10);
    SenDateLabel.setLabelFor(SenDateField);
    p.add(SenDateField);
    JLabel ScoreLabel = new JLabel(labels[5], JLabel.TRAILING);
    p.add(ScoreLabel);
    JTextField ScoreField = new JTextField(10);
    ScoreLabel.setLabelFor(ScoreField);
    p.add(ScoreField);
    JLabel ScrambleLabel = new JLabel(labels[6], JLabel.TRAILING);
    p.add(ScrambleLabel);
    JTextField ScrambleField = new JTextField(10);
    ScrambleLabel.setLabelFor(ScrambleField);
    p.add(ScrambleField);
    JLabel l = new JLabel(labels, JLabel.TRAILING);
    p.add(l);
    if(labels[i].equals("Middle Initial: "))
    textFieldLength = 5;
    System.out.println("Middle Initial");
    else
    textFieldLength = 10;
    JTextField textField = new JTextField(5);
    l.setLabelFor(textField);
    p.add(textField);
    //Lay out the panel.
    SpringUtilities.makeCompactGrid(p,
    7/*numPairs*/, 2, //rows, cols
    6, 6, //initX, initY
    6, 6); //xPad, yPad
    //Create and set up the window.
    JFrame frame = new JFrame("SpringForm2");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //Set up the content pane.
    p.setOpaque(true); //content panes must be opaque
    frame.setContentPane(p);
    //Display the window.
    frame.pack();
    frame.setVisible(true);
    public static void main( String[] args )
    //Schedule a job for the event-dispatching thread:
    //creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(new Runnable()
    public void run()
    createAndShowGUI();
    Message was edited by:
    poncho

    Swing related questions should be posted in the Swing forum.
    Don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the posted code retains its original formatting.
    [url http://java.sun.com/docs/books/tutorial/uiswing/layout/spring.html]How to Use Spring Layout

  • LocationAPI getLocation timeout don´t work

    Hey,
    I&acute;ve a Problem with the LocationAPI. I want to update my Position everey 500ms.
    Here my Code:
    while(true){
         try {
              location = locProvider.getLocation(5);          // Lokalisierung (timeout: Provider default)
              coord = location.getQualifiedCoordinates();     // Koordinaten holen                    
         } catch (LocationException locExc) {               // Provider in Timeout-Zeit nicht erreichbar
              status = false;
              coord = null;
         } catch (InterruptedException intExc) {
              status = false;
         if(coord != null){
              status = true;
              lat   = coord.getLatitude();          // Breitengrad     
              lon   = coord.getLongitude();          // L&auml;ngengrad
              hoehe = coord.getAltitude();          // H&ouml;he
              speed = location.getSpeed();          // Geschwindigkeit
         }else{
              status = false;
    }Problem: On my MobilePhone (Samsung Jet S8000) the Thread paused at "location = locProvider.getLocation(5)" (when I´ve no Signal). Even after the timeout (5s) it does not continue... when i´ve a signal it works fine... my samsung emulator don´t have this problem...
    where is the problem or how can i change the variable "status" after 5 seconds false?
    Thanks!

    Hey IceTi,
    Have a look at Timer and TimerTask* classes.
    Daniel

  • Nested Panels with SpringLayout

    I've been attempting to use nested JPanels, each with a SpringLayout. However, this seems to cause some very strange behaviour with component scrolling off the left edge of the window unless it's sized narrow. I've not used SpringLayout much, but I'm at a loss to explain it.
    I have:
        protected void setUpGUI() {
            //set up layout
            SpringLayout theLayout=new SpringLayout();
            super.getContentPane().setLayout(theLayout);
            //add EntryPane
            super.getContentPane().add(theEntryPane);
            theLayout.putConstraint(SpringLayout.NORTH,theEntryPane,5,SpringLayout.NORTH,super.getContentPane());
            theLayout.putConstraint(SpringLayout.WEST,theEntryPane,5,SpringLayout.WEST,super.getContentPane());
            theLayout.putConstraint(SpringLayout.EAST,super.getContentPane(),5,SpringLayout.EAST,theEntryPane);
            //set up buttons
            storeButton=new JButton("Store");
            refreshButton=new JButton("Refresh");
            //add buttons
            super.getContentPane().add(storeButton);
            theLayout.putConstraint(SpringLayout.NORTH,storeButton,5,SpringLayout.SOUTH,theEntryPane);
            theLayout.putConstraint(SpringLayout.WEST,storeButton,5,SpringLayout.WEST,super.getContentPane());
            theLayout.putConstraint(SpringLayout.SOUTH,super.getContentPane(),5,SpringLayout.SOUTH,storeButton);
            super.getContentPane().add(refreshButton);
            theLayout.putConstraint(SpringLayout.NORTH,refreshButton,5,SpringLayout.SOUTH,theEntryPane);
            theLayout.putConstraint(SpringLayout.WEST,refreshButton,5,SpringLayout.EAST,storeButton);
            theLayout.putConstraint(SpringLayout.SOUTH,super.getContentPane(),5,SpringLayout.SOUTH,refreshButton);
        }In my subclass of JFrame, and 'theEntryPane' is a subclass of JPanel which includes the following:
        protected void addComponent(Component comp){
            add(comp);
            theLayout.putConstraint(SpringLayout.WEST,comp, 5,SpringLayout.WEST,this);
            theLayout.putConstraint(SpringLayout.EAST,this,5,SpringLayout.EAST,comp);
            if(lastComponent==null){
                theLayout.putConstraint(SpringLayout.NORTH,comp,5,SpringLayout.NORTH,this);
            } else {
                theLayout.putConstraint(SpringLayout.NORTH,comp,3,SpringLayout.SOUTH,lastComponent);
            lastComponent=comp;
        }My subclass of JFrame has a similar method that simply passes the component on to theEntryPane. When I run it and add the following components:
    addComponent(new JLabel("Thing!"));
            addComponent(new JLabel("Thing!"));
            addComponent(new JLabel("Thing!"));The buttons at the bottom are off to the left, and only return when you make the window narrow. If I make my nested pane override getPreferredSize() to return Integer.MAX_VALUE for both dimensions, the buttons at the bottom (which are in a different container!) appear correctly but the top two labels in the nested frame suffer from the same problem.
    Can anyone shed any light onto what's going on here? It appears that the nested layouts are somehow interfering with one another.

    Found the error. Fixed now.

  • Nested SpringLayout panels

    I've been trying to organize some panels using SpringLayout, which I'm fairly new to.
    What I've got is a summary panel and below it a large table. The Summary panel is divided horizontally into three sub panels (contrasting background) each of which have a series of lable-value pairs. The central panel also has a table and a pie chart.
    I'm having problems with the overall height of the summary panel. I just can't get it to work sanely without setting the height to a contant, whereas I'd rather have it calculate the height from the contents.
    Inside the summary panel the SOUTH boundary is set relative to the SOUTH of the longest sub-panel. This contstraint just doesn't seem to have any effect.
    I've also tried generating a Spring for the height of the summary panel and explicitly setting that as the height in the outer SpringLayout, that doesn't seem to make any difference. Unless I force the height of the summary panel constant it persitently crops about a third of it's display.

    Found the error. Fixed now.

  • SpringLayout in J2SE6.0 : Can't make sense of Sun's statement

    Sun advertises binary incompatibilities for pre-1.6 programs when run in a 1.6 JRE. I have an app that is now completely broken with 1.6, and I can't make sense of Sun's explanation (quoted below in its entirety).
    First of all, the two sentences in the statement
    "In Java SE 6, SpringLayout maintains the order in which springs have been set. As a result, specifying springs is no longer order-dependent."
    seem to directly contradict each other. But more to the point, I don't understand their description of what constitutes an overly constrained layout. They say in one place that two springs on an axis are necessary and a third would result in some redundancy. But then they say that the first of the following two statements was ignored in j2SE5.0
    constraints.setX(xSpring);
    constraints.setConstraint("East", eastSpring);Why is that? If you only constrain the east side of an object, why is the placement on the X axis redundant? I would think that either an X or a width constraint is needed. My code is predicated on that (apparently erroneous) understanding, and now I get over 60 "spring xyz is cyclic" errors using J2SE6.0.
    I think if I understood the example above I'd know what's wrong with my code, but I just can't see how you can constrain an object fully with a single spring.
    Here's the full text of Sun's incompatibility statement from the release notes.
    [i]8. Specifying constraints on SpringLayout was order dependent
    SpringLayout specifies three Springs along each axis which dictate the size and position of a component. Only two Springs are needed along each axis, with the third being derived. If three Springs are specified, the layout is considered overly constrained and one of the Springs is dropped. Currently, the behavior for determining which Spring to drop is not intuitive and leads to ordering problems.
    In Java SE 6, SpringLayout maintains the order in which springs have been set. As a result, specifying springs is no longer order-dependent. Support for centering and aligning along the baseline has also been added.
    Programs affected by this change can contain statements that were redundant in J2SE 5.0.
    For example:
    constraints.setX(xSpring);
    constraints.setConstraint("East", eastSpring);
    In J2SE 5.0, the setX call in effect resulted in nothing, in Java SE 6, the setX call is meaningful and different behavior will result.
    _____________________________________________________

    i thought i'd mention a little more. if i change my constructor to something like
    public MyClass() {
        System.out.println("Before load().");
        load();
        System.out.println("After load().");
    }the before and after lines print but the load method's printf will not print until my program ends. still puzzled.

  • Problem with springlayout

    I'm pretty new in java programming and just got a question.
    I used one of the spring layout exampels on java.sun.com and wanted to develop it a little. Just to put another JLabel into the JFrame.
    Here is my code
    import javax.swing.SpringLayout;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JTextField;
    import java.awt.Container;
    public class SpringDemo2 {
         * Create the GUI and show it.  For thread safety,
         * this method should be invoked from the
         * event-dispatching thread.
        private static void createAndShowGUI() {
            //Make sure we have nice window decorations.
            JFrame.setDefaultLookAndFeelDecorated(true);
            //Create and set up the window.
            JFrame frame = new JFrame("SpringDemo2");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            //Set up the content pane.
            Container contentPane = frame.getContentPane();
            SpringLayout layout = new SpringLayout();
            contentPane.setLayout(layout);
            //Create and add the components.
            JLabel label = new JLabel("Label: ");
            JLabel test = new JLabel("hej! ");
            JTextField textField = new JTextField("Text field", 15);
            contentPane.add(label);
            contentPane.add(test);
            contentPane.add(textField);
            //Adjust constraints for the label so it's at (5,5).
            layout.putConstraint(SpringLayout.WEST, label, 5, SpringLayout.WEST, contentPane);
            layout.putConstraint(SpringLayout.NORTH, label, 5, SpringLayout.NORTH, contentPane);
            layout.putConstraint(SpringLayout.WEST, test, 5, SpringLayout.EAST, contentPane);
            layout.putConstraint(SpringLayout.NORTH, test, 5, SpringLayout.NORTH, label);  
            //Adjust constraints for the text field so it's at
            //(<label's right edge> + 5, 5).
            layout.putConstraint(SpringLayout.WEST, textField, 5, SpringLayout.EAST, label);
            layout.putConstraint(SpringLayout.NORTH, textField, 5, SpringLayout.NORTH, contentPane);
            //Display the window.
            frame.pack();
            frame.setVisible(true);
        public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
    }The problem is that the JLabel with the text "hej" doesn't get visible.
    someone who got a solution?
    thanks!

    you can do this if you want the components to be visible during startup, without manually resizing the JFrame:
    layout.putConstraint(SpringLayout.EAST, contentPane, 5, SpringLayout.EAST, textField);
    layout.putConstraint(SpringLayout.SOUTH, contentPane, 5, SpringLayout.SOUTH, textField);
    or
    frame.pack();
    frame.setSize(250, 100);
    frame.setVisible(true);
    hth.

  • SpringLayout - resize

    hi
    I have JPanel that contains rows of JPanels.
    Each row have her own components inside.
    All the JPanels use SpringLayout (the main and the rows).
    In run time one of the rows changes her height (heigher) and add more components.
    My problem is that when I add new component to one of the rows and change the row's height in runn time nothing happend.....
    Tanks, Yaniv

    If I'm not mistaken, you can't change the width and height of a component unless the JPanel they are on, has a null-layout JPanel.setLayout(null). You can use component.setSize(x,y) or component.setBounds(x,y,width,height) to place them correctly on the JPanel.
    Maybe you can accomplish something with getPreferredSize() as well, but I'm not that familiar with the function.

  • Question involving getlocation / set location

    Hello,
    So here's my problem... For simplicities sake, I'll just skip to the point. I'm trying to make an shape move from where it is on the screen but based on a fixed ratio. So I'm trying to take the location of object x, and increase it's x and y coordinates for its location by say 20%.
    I'd like to be able to do something like this.
    private int x;
    private int y;
    private int yprime;
    private int xprime;
    this.getLocation(x,y);
    yprime = y*1.2;
    xprime = y*1.2;
    this.setLocation(xprime,yprime);The problem is I get an error message saying the shapes package I'm using cannot use the method getLocation(int, int), or something along those lines. What am I doing wrong!?
    Edited by: ApeXX on Feb 15, 2010 6:17 PM

    ApeXX wrote:
    I'm sorry, I should have been more clear. I'm using a special package "wheels" designed for a learning java course. This shapes package does include a method called "getLocation".And hopefully has an api that you can use to see if you're calling the method correctly. As I noted above, does your code even compile? You seem to be trying to convert an int (xprime and yprime) into a double by setting it equal to a double. Or are xprime and yprime really double variables and this is why the compiler complains when you try to use them in getLocation or setLocation?

  • ***lapi   getLocation Exception **please helpe***I am getting crazy*****

    Hi frnd
    Recently I am working on a location based project on mobile.I have search the net and found many source code for get BTS CELL ID and coordinates and all the source code have the same code.
    but when I install on mobile I get *{color:#ff0000}location Exception{color}*{color:#ff0000}...
    {color}I have search the net and every where and yet not found the solution, even i am using Nokia N71 which supports location based api.
    guys Really i am getting crazy, there should be a solution .... please help me
    there is a program in simbian "celltrack", It easily shows the BTS information,
    if any body has Idea please help me... thankssssssssss
    ...piece of code ....
    LocationProvider lp=*null*;
    Location location=*null*;
    try
    Criteria cr = new Criteria();
    //cr.setHorizontalAccuracy(1000);
    //cr.setVerticalAccuracy(1000);
    //cr.setPreferredPowerConsumption(Criteria.POWER_USAGE_LOW);
    lp = LocationProvider.getInstance(cr);
    if(lp.getState()==1)
    message="provider! is valid" + "\n";
    //timeout
    {color:#ff0000}location = lp.getLocation(60); // Exception happens here
    ....{color}
    catch(LocationException e)
    btsInfo +="1:"+e.toString()+ "\n";

    Konapalli.Gopi wrote:
    i am using websphere application server to deploy the web application.
    javax.mail.SendFailedException: Sending failed;
    nested exception is:
         class javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
    nested exception is:
         java.net.SocketException: Cannot find the specified class java.security.PrivilegedActionException: java.lang.ClassNotFoundException: com.ibm.websphere.ssl.protocol.SSLSocketFactory
    I would guess
    com.ibm.websphere.ssl.protocol.SSLSocketFactoryis not on your classpath.

  • SPDiagnosticsServiceBase.GetLocal causes exception during SPFeatureReceiver.FeatureInstalled

    If a SharePoint farm solution is deployed using Sever Object Model or PowerShell calling the SPDiagnosticsServiceBase.GetLocal in the SPFeatureReceiver.FeatureInstalled code causes an exception:
    The installation of features failed during deployment of the solution.
    CAS_SP : Configsetting with key 'CAS.SharePoint.Common.TypeMappings' could not be set 'CAS.SharePoint.Common.ServiceLocation.ServiceLocationConfigData' with type 'CAS.SharePoint.Common.ServiceLocation.ServiceLocationConfigData'. The technical exception was: CAS.SharePoint.Common.Logging.LoggingException: One or more error occurred while writing messages into the log.\r\nThe error while writing to the EventLog was:An exception has occurred.
    ExceptionType: 'SPDuplicateObjectException'
    ExceptionMessage: 'An object of the type CAS.SharePoint.Common.Logging.DiagnosticsService named "" already exists under the parent Microsoft.SharePoint.Administration.SPFarm named "SharePoint_Config_c8ae0268-40ff-4bea-82f0-eddcd464e806". Rename your object or delete the existing object.'
    StackTrace: ' at Microsoft.SharePoint.Administration.SPConfigurationDatabase.StoreObject(SPPersistedObject obj, Boolean storeClassIfNecessary, Boolean ensure)
    at Microsoft.SharePoint.Administration.SPConfigurationDatabase.Microsoft.SharePoint.Administration.ISPPersistedStoreProvider.PutObject(SPPersistedObject persistedObject, Boolean ensure)
    at Microsoft.SharePoint.Administration.SPPersistedObject.BaseUpdate()
    at Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.Update()
    at Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.GetLocalToFarm[T](SPFarm farm)
    at Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.GetLocal[T]()
    at CAS.SharePoint.Common.Logging.TraceLogger.Trace(String message, Int32 eventId, TraceSeverity severity, String category)
    at CAS.SharePoint.Common.Logging.SharePointLogger.WriteToDeveloperTrace(String message, Int32 eventId,
    The same solution deployed using Central Administration tool works fine. The code also works fine while executing it from command line application.
    I have reproduced this problem on two SharePoint Servers and one Foundation instance.
    It seems as a SharePoint bug, but is there any workaround you know? How to report it to the SharePoint developers team ?
    Mariusz

    The farms that you are doing this on, are they multiserver farms (multiple wfes), or have you repro'd on a single server farm?  It almost seems as though some config cache is having a problem, or psconfig is clashing with itself (if it involves multiple
    servers). 

Maybe you are looking for