3

Details

I have some questions concerning the javax.swing.Box class (please see http://docs.oracle.com/javase/7/docs/api/javax/swing/Box.html for documentation). I have recently updated my dev environment to Java 7u5 and am in the process of recompiling some old projects... however, when dealing with a project which contains the javax.swing.Box class, I get a "constructor Box in class Box cannot be applied to given types; required: no arguments found: int" error. These worked perfectly before.

Questions

Does anyone have any thoughts as to why this is happening? The constructor doesn't look like it has changed. Is there something I'm missing? Can't for the life of me find a documented change anywhere. Please see the sample code below which recreates the error.

Sample Code

import java.awt.*;
import javax.swing.*;

public class BoxTest
{
    private JFrame $_frame;
    private JPanel $_panel;
    private Box $_box;
    private JButton $_button1, $_button2;

    public BoxTest()
    {
        $_frame = new JFrame("Box Test");
        $_panel = new JPanel(new BorderLayout());
        $_box = new Box(BoxLayout.Y_AXIS);
        $_button1 = new JButton("Test Button 1");
        $_button2 = new JButton("Test Button 2");
    }

    public void buildGUI()
    {
        $_box.add($_button1);
        $_box.add($_button2);

        $_panel.add(BorderLayout.EAST, $_box);

        $_frame.getContentPane().add(this.$_panel);
        $_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        $_frame.setBounds(50, 50, 300, 300);
        $_frame.setVisible(true);
    }

    public static void main(String[] args)
    {
        BoxTest boxTest = new BoxTest();
        boxTest.buildGUI();
    }
}

thanks!

Tharwen
  • 3,057
  • 2
  • 24
  • 36
Hegemon
  • 433
  • 7
  • 21
  • It can be the bugs attached with the new versions of the `JDK`, one such is described here in this [thread](http://stackoverflow.com/q/9849950/1057230) and another one [here](http://stackoverflow.com/q/8081559/1057230). Since it's working fine on my Platform Windows 7 with `java version "1.7.0_03" Java(TM) SE Runtime Environment (build 1.7.0_03-b05)` – nIcE cOw Aug 14 '12 at 14:36
  • 3
    Is there a `Box` class in the BoxTest package ? – gontard Aug 14 '12 at 14:38
  • I cannot reproduce the error using your code. It compiles and runs fine for me usig Java 1.7. – Hovercraft Full Of Eels Aug 14 '12 at 14:49
  • Solved: Thanks for the input guys! Something Gontard said had me thinking *No, it's in the swing package...*, but then I had a sneaking suspicion, double checked and sure enough, since I was recompiling a few files in the same folder I found an erroneous Box.class file which was left over from a previous project and it was overriding the intended one. Moral of the story - Always check classes, especially ones with such simple names. Much appreciated! – Hegemon Aug 14 '12 at 15:01
  • 2
    @gontard should change his comment into an answer so that it can be accepted. – Hovercraft Full Of Eels Aug 14 '12 at 15:07
  • @HovercraftFullOfEels : Agreed :-) – nIcE cOw Aug 14 '12 at 15:15

1 Answers1

4

Is there a Box class in the BoxTest package ?

gontard
  • 28,720
  • 11
  • 94
  • 117