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.

Similar Messages

  • 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!!!

  • 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

  • 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.

  • Serialization using XMLEncoder/XMLDecoder - problems for SpringLayout

    I am using JDK 1.4.0 (obviously, as I have problems with XMLEncoder... :o)
    What I need to do is create a JFrame with some Swing components inside (JPanel's, JLabel's, etc.), to save it as an XML file and be able to restore it later.
    Everything went OK at the beginning, but there came the time to manage the layout part. For various reasons, the most appropriate layout manager for my application is SpringLayout.
    The first step was again OK: when defining a SpringLayout for a panel, this property was transferred to the XML by XMLEncoder and restored by XMLDecoder.
    But then, the happy days are over! In order for a SpringLayout to work, one must obviously define lots of SpringLayout.Constraints, using Spring's. But none of these things are transferred by XMLEncoder to the XML.
    And, quite naturally, even if I modify manually the XML to include some constraint info, the XMLDecoder won't read that info!
    Does anybody know if there is any trick about this? Or is there a known bug concerning the serialization of Spring's, and you know about a workaround?
    Thanks a lot,
    Adrian

    Hi Adrian, there are no persistence delegates defined for SpringLayout and its children.
    I spent quite some time over the last six months trying to get SpringLayouts to save
    correctly - but failed. There are two bugs in the way - both of which should be fixed for
    1.4.1 (I think). One was in SpringLayout - the other in XMLEncoder itself:
    http://developer.java.sun.com/developer/bugParade/bugs/4679556.html
    One thing you said in your note that I thought Id comment on. You can edit the XML file manually
    and this will (probably) lead to a solution. The XMLDecoder is an interpreter - it doesn't need access
    to persistence delegates or require any knowledge of the swing APIs to work.
    Hope that helps.
    Philip

  • BorderLayout vs SpringLayout : resizing application user interface

    I have an application that resized (i.e. maximized to fill monitor) readily when I used BorderLayout. After changing the layout to SpringLayout, I am happier with my user interface but it does not maximize.
    Actually it does maximize, but it leaves the rest of the larger screen blank. Any ideas on how to fix that? So that the entire user interface fills the window whether maximized or smaller?
    Thanks.

    Follow the link to the Swing tutorials from the topic listing page for this forum and go through the trail on Laying out Components in a Container. After that, if you have a specific issue with your layout, post a [SSCCE (Short, Self Contained, Compilable and Executable, Example Program)|http://mindprod.com/jgloss/sscce.html] that demonstrates the problem.
    When you do so, use code tags to post codes -- [code]CODE[/code] will display asCODEOr click the CODE button and paste your code between the {code} tags that appear.
    db

  • 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).

  • Right alignment with SpringLayout

    I've just started playing with SpringLayout. I've been using mostly BoxLayout up to now but I thought it was time I gave an alternative a go. BoxLayout has it's own erratic sizing problems.
    Anyway I'm trying to generate a sub panel like:
    Title (centered)
    Quantity1 888
    Quantity2 99
    <Table> <PieChart>
    With the numbers against the RHS of the box
    First thing I've found is that putting a zero length Spring between the NORTH of the lable and the value doesn't work, I have to set both relative to the previous line or (mysteriously) no vertical separation happens at all.
    Here's the code that adds a lable/value pair:
        private static Component addPair(Component prev, String label, JLabel value) {
            Container c = prev.getParent();
            SpringLayout l = (SpringLayout)c.getLayout();
            JLabel nameLab  = new JLabel(label);
            c.add(nameLab);
            c.add(value);
            l.getConstraints(nameLab).setHeight(Spring.constant(12));
            l.putConstraint(SpringLayout.NORTH, nameLab, 2, SpringLayout.SOUTH, prev);
            l.putConstraint(SpringLayout.WEST, nameLab, 10, SpringLayout.WEST, c);
            l.putConstraint(SpringLayout.EAST, c, 10, SpringLayout.EAST, value);
            l.putConstraint(SpringLayout.NORTH, value, 2, SpringLayout.SOUTH, prev);
         //   l.putConstraint(SpringLayout.SOUTH, nameLab, 0, SpringLayout.SOUTH, value);
            l.putConstraint(SpringLayout.WEST, value, Spring.constant(10, 10, 500),
                    SpringLayout.EAST, nameLab);
            return nameLab;
        }prev being the label from the previous pair.
    It refuses to right align the value lable. It looks like the constraint between the EAST of the value and the EAST of the container has no effect. I've also set the alignment in the JLabels to RIGHT, which has no effect.
    If I take out the constraint between the WEST of the value and the EAST of the lable It plonks the lable and value on top of one another.
    Furthermore, though the hieght of the pie chart is set explictly by a constraint, the LayoutManager seems incapable of producing a sensible minimum height for the overall box.
    All of which makes me wonder if SpringLayout is worth persevering with or if there are just tricks and gaps I have to learn to deal with.

    I think I've cracked it. Some things they don't tell you about SpringLayout, which I found out mostly by reading the source.
    putConstraint is not symetrical. Logically
    putConstraint(SpringLayout.WEST, container, 10, SpringLayout.WEST,
    valueLab);might be expected to imply:
    putConstraint(SpringLayout.WEST, valueLab, -10,  SpringLayout.WEST,
    container);But it doesn't. Only the first object in the call is actually constrained.
    Secondly the "overconstraint" thing is very arbitary. Setting the NORTH or WEST clears the EAST or SOUTH wherease setting the EAST or SOUTH clears the height or width. Hence if you set, for example, EAST and WEST then it's essential to set EAST first, otherwise WEST will be ignored and the WEST will be set from EAST - width. There seems to be no way of clearing a constraint once set, and constraints are intialised from the objects bounds, so NORTH and WEST are always set to zero initially. If seems like the contraints are almost always going to be treated as overconstrained.
    Parallel constraints don't get combined, the last one specified predominates so there doesn't seem any sensible way of, for example, setting the width of a container based on the maximum of the widths of fields contained.
    There seems to be no use of the springiness of Spring objects. They are merely treated as min, pref and max values. Logically stretchiness should be used to distribute space, and to cope with springs in parallel. It doesn't appear any of that stuff is done.

  • SpringLayout fails to resize

    re: Java Tutorial, How to Use SpringLayout
    http://java.sun.com/docs/books/tutorial/uiswing/layout/spring.html
    run SpringDemo3.java, given as an example on this page.
    resize (expand) the frame by grabbing a border.
    this works.
    now attempt to resize (contract) the frame the same way.
    this does not work.
    why?
    the code to create and lay out the frame is given below:
    private static void createAndShowGUI() {
        //Make sure we have nice window decorations.
        JFrame.setDefaultLookAndFeelDecorated(true);
        //Create and set up the window.
        JFrame frame = new JFrame("SpringDemo3");
        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: ");
        JTextField textField = new JTextField("Text field", 15);
        contentPane.add(label);
        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);
        //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);
        //Adjust constraints for the content pane: Its right
        //edge should be 5 pixels beyond the text field's right
        //edge, and its bottom edge should be 5 pixels beyond
        //the bottom edge of the tallest component (which we'll
        //assume is textField).
        layout.putConstraint(SpringLayout.EAST, contentPane,
                             5,
                             SpringLayout.EAST, textField);
        layout.putConstraint(SpringLayout.SOUTH, contentPane,
                             5,
                             SpringLayout.SOUTH, textField);
        //Display the window.
        frame.pack();
        frame.setVisible(true);
    }

    so no one has anything to add... anyone else having this issue?
    and what happened to the discussion forum for the past few/several month?!?  it was inaccessible...

  • Centring items using SpringLayout

    I'm writing a dictionary program that uses Spring Layout to position things in exactly the way I want them.
    However, some elements, such as the results table, or the masses of buttons to perform searches, don't stay centred and I don't know how to do this using Spring Layout.
    Snippets of my code below. Centred Dictionary Window just sets the size, background colour, etc. There are 5 of each element (eg "Not" ComboBoxes, etc) except Operator ComboBoxes, of which there are 4. and yeah I understand that I can use 'object arrays' to shorten my code and avoid duplication but I've not worked out exactly how to do that yet >.<
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.lang.*;
    import java.io.*;
    public class searchWindowFrame extends CentredDictionaryWindow {
    //Title image
              JLabel searchImage = new JLabel(new ImageIcon("resources/SearchImage.jpg"));
              boxFont = new Font("Tahoma", Font.PLAIN, 12);
              //First 'Not' ComboBox
              String[] notItems = { "", "NOT" };
              notCombo = new JComboBox(notItems);
              notCombo.setPreferredSize(new Dimension(95, 40));
              notCombo.setBackground(new Color(241, 239, 240));
              notCombo.setForeground(new Color(93, 58, 64));
              notCombo.setFont(boxFont);
              notCombo.setEnabled(true);
              //First 'Dictionary Type' ComboBox
              String[] dictTypeItems = { "<Dictionary Type>", "Orthography", "Pronunciation" };
              dictTypeCombo = new JComboBox(dictTypeItems);
              dictTypeCombo.setPreferredSize(new Dimension(135, 40));
              dictTypeCombo.setBackground(new Color(241, 239, 240));
              dictTypeCombo.setForeground(new Color(93, 58, 64));
              dictTypeCombo.setFont(boxFont);
              dictTypeCombo.setEnabled(true);
              //First 'Search Type' ComboBox
              String[] searchTypeItems = { "<Search Type>", "Contains", "Starts With",
                   "Ends With", "Minimal Pairs" };
              searchTypeCombo = new JComboBox(searchTypeItems);
              searchTypeCombo.setPreferredSize(new Dimension(125, 40));
              searchTypeCombo.setBackground(new Color(241, 239, 240));
              searchTypeCombo.setForeground(new Color(93, 58, 64));
              searchTypeCombo.setFont(boxFont);
              searchTypeCombo.setEnabled(true);
              //First 'Query' TextField
              searchTermField = new JTextField("<Query>", 10);
              searchTermField.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
              searchTermField.setPreferredSize(new Dimension(100, 40));
              searchTermField.setBackground(new Color(249, 249, 249));
              searchTermField.setForeground(new Color(93, 58, 64));
              searchTermField.setFont(boxFont);
              //First 'Operator' ComboBox
              String[] operatorItems = { "", "AND", "OR" };
              operatorCombo = new JComboBox(operatorItems);
              operatorCombo.setPreferredSize(new Dimension(95, 40));
              operatorCombo.setBackground(new Color(241, 239, 240));
              operatorCombo.setForeground(new Color(93, 58, 64));
              operatorCombo.setFont(boxFont);
              operatorCombo.setEnabled(true);
    //Panel containing Not Combo Boxes
              firstQueryPanel = new JPanel();
              firstQueryPanel.setLayout(new GridLayout(5, 0, 10, 10));
              firstQueryPanel.setBackground(new Color(241, 239, 240));
              firstQueryPanel.setBorder(new EmptyBorder(10, 10, 0, 0));
              firstQueryPanel.add(notCombo);
              firstQueryPanel.add(notComboTwo);
              firstQueryPanel.add(notComboThree);
              firstQueryPanel.add(notComboFour);
              firstQueryPanel.add(notComboFive);
              //Panel containing Dictionary Type Combo Boxes
              secondQueryPanel = new JPanel();
              secondQueryPanel.setLayout(new GridLayout(5, 0, 10, 10));
              secondQueryPanel.setBackground(new Color(241, 239, 240));
              secondQueryPanel.setBorder(new EmptyBorder(10, 0, 0, 0));
              secondQueryPanel.add(dictTypeCombo);
              secondQueryPanel.add(dictTypeComboTwo);
              secondQueryPanel.add(dictTypeComboThree);
              secondQueryPanel.add(dictTypeComboFour);
              secondQueryPanel.add(dictTypeComboFive);
              //Panel containing Search Type Combo Boxes
              thirdQueryPanel = new JPanel();
              thirdQueryPanel.setLayout(new GridLayout(5, 0, 10, 10));
              thirdQueryPanel.setBackground(new Color(241, 239, 240));
              thirdQueryPanel.setBorder(new EmptyBorder(10, 0, 0, 0));
              thirdQueryPanel.add(searchTypeCombo);
              thirdQueryPanel.add(searchTypeComboTwo);
              thirdQueryPanel.add(searchTypeComboThree);
              thirdQueryPanel.add(searchTypeComboFour);
              thirdQueryPanel.add(searchTypeComboFive);
              //Panel containing Query Text Fields
              fourthQueryPanel = new JPanel();
              fourthQueryPanel.setLayout(new GridLayout(5, 0, 10, 10));
              fourthQueryPanel.setBackground(new Color(241, 239, 240));
              fourthQueryPanel.setBorder(new EmptyBorder(10, 0, 0, 0));
              fourthQueryPanel.add(searchTermField);
              fourthQueryPanel.add(searchTermFieldTwo);
              fourthQueryPanel.add(searchTermFieldThree);
              fourthQueryPanel.add(searchTermFieldFour);
              fourthQueryPanel.add(searchTermFieldFive);
              //Panel containing Operator Combo Boxes
              fifthQueryPanel = new JPanel();
              fifthQueryPanel.setLayout(new GridLayout(4,0,10,10));
              fifthQueryPanel.setBackground(new Color(241, 239, 240));
              fifthQueryPanel.setBorder(new EmptyBorder(10, 0, 0, 10));
              fifthQueryPanel.add(operatorCombo);
              fifthQueryPanel.add(operatorComboTwo);
              fifthQueryPanel.add(operatorComboThree);
              fifthQueryPanel.add(operatorComboFour);
              //Search button
              searchButton = new JButton("Search");
              searchButton.setFont(boxFont);
              searchButton.setBackground(new Color(249, 249, 249));
              searchButton.setForeground(new Color(93, 58, 64));
              searchButton.setToolTipText("Search with the set parameters");
              searchButton.setPreferredSize(new Dimension(100, 40));
              searchButton.setFocusPainted(false);
              //Back button
              backButton = new JButton("< Back");
              backButton.setFont(boxFont);
              backButton.setBackground(new Color(249, 249, 249));
              backButton.setForeground(new Color(93, 58, 64));
              backButton.setPreferredSize(new Dimension(100, 40));
              backButton.setFocusPainted(false);
              //Exit button
              exitButton = new JButton("Exit");
              exitButton.setFont(boxFont);
              exitButton.setBackground(new Color(249, 249, 249));
              exitButton.setForeground(new Color(93, 58, 64));
              exitButton.setPreferredSize(new Dimension(100, 40));
              exitButton.setFocusPainted(false);
    layout = new SpringLayout();
              getContentPane().setLayout(layout);
              layout.putConstraint(SpringLayout.NORTH, searchImage, 10, SpringLayout.NORTH, getContentPane());
              layout.putConstraint(SpringLayout.EAST, searchImage, 0, SpringLayout.EAST, getContentPane());
              layout.putConstraint(SpringLayout.NORTH, firstQueryPanel, 10, SpringLayout.SOUTH, searchImage);
              layout.putConstraint(SpringLayout.WEST, secondQueryPanel, 10, SpringLayout.EAST, firstQueryPanel);
              layout.putConstraint(SpringLayout.NORTH, secondQueryPanel, 10, SpringLayout.SOUTH, searchImage);
              layout.putConstraint(SpringLayout.WEST, thirdQueryPanel, 10, SpringLayout.EAST, secondQueryPanel);
              layout.putConstraint(SpringLayout.NORTH, thirdQueryPanel, 10, SpringLayout.SOUTH, searchImage);
              layout.putConstraint(SpringLayout.WEST, fourthQueryPanel, 10, SpringLayout.EAST, thirdQueryPanel);
              layout.putConstraint(SpringLayout.NORTH, fourthQueryPanel, 10, SpringLayout.SOUTH, searchImage);
              layout.putConstraint(SpringLayout.WEST, fifthQueryPanel, 10, SpringLayout.EAST, fourthQueryPanel);
              layout.putConstraint(SpringLayout.NORTH, fifthQueryPanel, 10, SpringLayout.SOUTH, searchImage);
              layout.putConstraint(SpringLayout.SOUTH, backButton, -10, SpringLayout.SOUTH, getContentPane());
              layout.putConstraint(SpringLayout.WEST, backButton, 10, SpringLayout.WEST, getContentPane());
              layout.putConstraint(SpringLayout.WEST, exitButton, 10, SpringLayout.EAST, backButton);
              layout.putConstraint(SpringLayout.SOUTH, exitButton, -10, SpringLayout.SOUTH, getContentPane());
              layout.putConstraint(SpringLayout.EAST, helpButton, -10, SpringLayout.WEST, searchButton);
              layout.putConstraint(SpringLayout.SOUTH, helpButton, -10, SpringLayout.SOUTH, getContentPane());
              layout.putConstraint(SpringLayout.SOUTH, searchButton, -10, SpringLayout.SOUTH, getContentPane());
              layout.putConstraint(SpringLayout.EAST, searchButton, -10, SpringLayout.EAST, getContentPane());
              getContentPane().setBackground(new Color(241, 239, 240));
              getContentPane().add(searchImage);
              getContentPane().add(firstQueryPanel);
              getContentPane().add(secondQueryPanel);
              getContentPane().add(thirdQueryPanel);
              getContentPane().add(fourthQueryPanel);
              getContentPane().add(fifthQueryPanel);
              getContentPane().add(backButton);
              getContentPane().add(exitButton);
              getContentPane().add(searchButton);
    ...

    -__- On searchWindowFrame I want to centre all 24 input components. On resultsFrame I want to centre the scroll pane containing the JTable.
    To say I rewrote most of the program I had to completely redo this to get it to run, nor can I even use them all because that's 'too much', so that was fun.
    Like I said, I can centre things, just when the window resizes, it doesn't move with it.
    Originally the window is set to the right size, so everything is in its correct place.
    import javax.swing.*;
    import java.awt.*;
    import java.io.*;
    public class searchFrame extends JFrame
         public searchFrame()
              setTitle("Dictionary A'la Lewis");
              // Get the toolkit for reading System information
              Toolkit tk = Toolkit.getDefaultToolkit();
              // Get the dimensions of the screen
              Dimension screenDimension = tk.getScreenSize();
              // Set the size
              setSize(620, 535);
              // Centre window on screen
              setLocation(new Point((screenDimension.width - 600) / 2, (screenDimension.height - 535) / 2));
              JComboBox notCombo = new JComboBox();
              notCombo.setPreferredSize(new Dimension(95, 40));
              notCombo.setEnabled(true);
              JComboBox notCombo2 = new JComboBox();
              notCombo2.setPreferredSize(new Dimension(95, 40));
              notCombo2.setEnabled(true);
              JComboBox dictionaryType = new JComboBox();
              dictionaryType.setPreferredSize(new Dimension(95, 40));
              dictionaryType.setEnabled(true);
              JComboBox dictionaryType2 = new JComboBox();
              dictionaryType2.setPreferredSize(new Dimension(95, 40));
              dictionaryType2.setEnabled(true);
              JPanel notPanel = new JPanel();
              JPanel dictionaryPanel = new JPanel();
              notPanel.setLayout(new GridLayout(2, 0, 10, 10));
              notPanel.add(notCombo);
              notPanel.add(notCombo2);
              dictionaryPanel.setLayout(new GridLayout(2, 0, 10, 10));
              dictionaryPanel.add(dictionaryType);
              dictionaryPanel.add(dictionaryType2);
              //Search button
              JButton searchButton = new JButton("Search");
              //Back button
              JButton backButton = new JButton("< Back");
              //Exit button
              JButton exitButton = new JButton("Exit");
              SpringLayout layout = new SpringLayout();
              getContentPane().setLayout(layout);
              layout.putConstraint(SpringLayout.NORTH, notPanel, 10, SpringLayout.NORTH, getContentPane());
              layout.putConstraint(SpringLayout.WEST, notPanel, 10, SpringLayout.WEST, getContentPane());
              layout.putConstraint(SpringLayout.NORTH, dictionaryPanel, 10, SpringLayout.NORTH, getContentPane());
              layout.putConstraint(SpringLayout.WEST, dictionaryPanel, 10, SpringLayout.EAST, notPanel);
              layout.putConstraint(SpringLayout.SOUTH, backButton, -10, SpringLayout.SOUTH, getContentPane());
              layout.putConstraint(SpringLayout.WEST, backButton, 10, SpringLayout.WEST, getContentPane());
              layout.putConstraint(SpringLayout.WEST, exitButton, 10, SpringLayout.EAST, backButton);
              layout.putConstraint(SpringLayout.SOUTH, exitButton, -10, SpringLayout.SOUTH, getContentPane());
              layout.putConstraint(SpringLayout.SOUTH, searchButton, -10, SpringLayout.SOUTH, getContentPane());
              layout.putConstraint(SpringLayout.EAST, searchButton, -10, SpringLayout.EAST, getContentPane());
              getContentPane().add(notPanel);
              getContentPane().add(dictionaryPanel);
              getContentPane().add(searchButton);
              getContentPane().add(backButton);
              getContentPane().add(exitButton);
         public static void main(String[] args) throws IOException
              JFrame search = new searchFrame();
              search.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              search.show();
    }On this one I want to keep the scroll pane centred (which it won't be at the mo) and I also want to keep the label saying so many results found to the scroll pane's right edge (which it won't be at the moment if the table moves because of the screen resizing).
    import javax.swing.*;
    import java.awt.*;
    import java.io.*;
    public class resultsFrame extends JFrame
         public resultsFrame()
              setTitle("Dictionary A'la Lewis");
              // Get the toolkit for reading System information
              Toolkit tk = Toolkit.getDefaultToolkit();
              // Get the dimensions of the screen
              Dimension screenDimension = tk.getScreenSize();
              // Set the size
              setSize(620, 535);
              // Centre window on screen
              setLocation(new Point((screenDimension.width - 600) / 2, (screenDimension.height - 535) / 2));
              //Search button
              JButton refineButton = new JButton("Refine");
              //Back button
              JButton homeButton = new JButton("Home");
              //Exit button
              JButton exitButton = new JButton("Exit");
              //Results Table
              JTable resultsTable = new JTable();
              resultsTable.doLayout();
              //Table's Scroll Pane
              JScrollPane tableScrollPane = new JScrollPane(resultsTable);
              tableScrollPane.setPreferredSize(new Dimension(520, 290));
              //Number of Results
              JLabel numberOfResults = new JLabel("0 results found.");
              SpringLayout layout = new SpringLayout();
              getContentPane().setLayout(layout);
              layout.putConstraint(SpringLayout.SOUTH, homeButton, -10, SpringLayout.SOUTH, getContentPane());
              layout.putConstraint(SpringLayout.WEST, homeButton, 10, SpringLayout.WEST, getContentPane());
              layout.putConstraint(SpringLayout.WEST, exitButton, 10, SpringLayout.EAST, homeButton);
              layout.putConstraint(SpringLayout.SOUTH, exitButton, -10, SpringLayout.SOUTH, getContentPane());
              layout.putConstraint(SpringLayout.SOUTH, refineButton, -10, SpringLayout.SOUTH, getContentPane());
              layout.putConstraint(SpringLayout.EAST, refineButton, -10, SpringLayout.EAST, getContentPane());
              layout.putConstraint(SpringLayout.NORTH, tableScrollPane, 10, SpringLayout.NORTH, getContentPane());
              layout.putConstraint(SpringLayout.WEST, tableScrollPane, 50, SpringLayout.WEST, getContentPane());
              layout.putConstraint(SpringLayout.EAST, numberOfResults, 0, SpringLayout.EAST, tableScrollPane);
              layout.putConstraint(SpringLayout.NORTH, numberOfResults, 5, SpringLayout.SOUTH, tableScrollPane);
              getContentPane().add(tableScrollPane);
              getContentPane().add(refineButton);
              getContentPane().add(homeButton);
              getContentPane().add(exitButton);
              getContentPane().add(numberOfResults);
         public static void main(String[] args) throws IOException
              JFrame result = new resultsFrame();
              result.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              result.show();
    }

Maybe you are looking for