哪位大虾帮帮忙啊!!!!我写了个JScrollPane(scrollPane),里面显示面板(p1),把scrollPane放在了面板(p2)上,然后把面板(p2)加到另外一个面板(p3)上,结果JScrollPane里面的那个面板(p1)出现在外面的面板(p3)的左上角paint的种方法都试了,没用。。急啊,这个游戏工程很快就要交了,请大神们帮帮忙。。感激不尽。源码如下
package mapEditor;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;import javax.swing.*;import life.MyCharacter;
import equipment.*;
public class GoodsPaneInBattle extends JPanel{
/**
 * 
 */
private static final long serialVersionUID = 749009572192293398L;
private JPanel goodsPane;
private JScrollPane scrollPane;
private ArrayList<Goods> goodslist=new ArrayList<Goods>();
private GoodsContainer gc[];//自己写的类,继承JButton
private JTextArea description;
private int gcnumber;

public GoodsPaneInBattle(){
setLayout(null);
setBounds(100,100,270,300);

goodslist=MyCharacter.getGoods();//MyCharacter为自己写的角色类
gcnumber=(goodslist.size()%4==0)?goodslist.size():4*(goodslist.size()/4+1);
gc=new GoodsContainer[gcnumber];

goodsPane=new JPanel();
goodsPane.setLayout(new GridLayout(gcnumber/4,4));

for(int i=0;i<gc.length;i++){
gc[i]=new GoodsContainer();
gc[i].setShowNumber(true);
gc[i].addMouseListener(new MouseAdapter(){
public void mouseEntered(MouseEvent e){
Goods goods=((GoodsContainer)e.getSource()).getGoods();
description.setText(goods.getFunction());
}
});
goodsPane.add(gc[i]);
}

for(int i=0;i<goodslist.size();i++){
gc[i].addGoods(goodslist.get(i));
}

scrollPane=new JScrollPane(goodsPane);
goodsPane.setBackground(new Color(200,180,130));
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
add(scrollPane);
scrollPane.setBounds(5,5,getBounds().width-10,getBounds().height-50);


                 //scrollPane下面的textArea
description=new JTextArea();
description.setForeground(Color.green);
description.setFont(new Font("华文新魏",Font.ITALIC,20));
description.setBounds(10,getBounds().height-40,getBounds().width-10,40);
description.setEditable(false);
description.setLineWrap(true);
description.setOpaque(false);
add(description);
}
public void paintComponent(Graphics g){
super.paintComponents(g);
Graphics2D gd=(Graphics2D)g;
gd.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
int w=getWidth();
int h=getHeight();
gd.setPaint(new GradientPaint(0,0,new Color(80,80,80),0,h,new Color(110,110,110),true));
gd.fillRoundRect(0,0,w,h,20,20);
gd.setColor(new Color(200,200,200));
gd.setStroke(new BasicStroke(3));
gd.drawRoundRect(5,scrollPane.getBounds().height+8,w-10,h-scrollPane.getBounds().height-10,20,20);
}

}import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JFrame;
import javax.swing.JPanel;import life.MyCharacter;public class Test extends JFrame{
private JPanel p;
private GoodsPaneInBattle gpb;
public Test(){
setBounds(100,100,800,600);
setVisible(true);
setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

p=new JPanel(){
public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D gd=(Graphics2D)g;
gd.drawImage(getToolkit().getImage("c:users/samsung/desktop/b1.jpg"),0,0,getWidth(),getHeight(),this);
}
};
getContentPane().add(p);
p.setBounds(0,0,800,600);
p.setLayout(null);

gpb=new GoodsPaneInBattle();
p.add(gpb);
}
//主方法
public static void main(String args[]){
new Test();
}}