On Mac OS X 10.5.8, Eclipse 3.4.2 and Xcode 3.1.4, the example below builds and runs using recent revisions of either Java 1.5 or Java 1.6. As Xcode includes the JDK, what version of Mac OS X and Xcode are you using?
Also verify that your Swing project hasn't inadvertently included SWT.
Addendum: Check these two dialogs:
Eclipse > Preferences > Java > Build Path
Eclipse > Preferences > Java > Installed JREs
You should see references to /System/Library/Frameworks/JavaVM.framework/
.
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
public class X {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new JPanel() {
private final int SIZE = 200;
private final int INSET = 20;
@Override
public Dimension getPreferredSize() {
return new Dimension(SIZE, SIZE);
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setColor(Color.blue);
Line2D line1 = new Line2D.Double(INSET, INSET,
getWidth() - INSET, getHeight() - INSET);
Line2D line2 = new Line2D.Double(getWidth() - INSET,
INSET, INSET, getHeight() - INSET);
g2.setStroke(new BasicStroke(16,
BasicStroke.CAP_ROUND,
BasicStroke.JOIN_BEVEL));
g2.draw(line1);
g2.draw(line2);
}
});
frame.pack();
frame.setVisible(true);
}
}