so im making this program that displays circles connected with lines, but i have a problem with the JScrollPane, the scrollbars arent working. Im creatin a Jpanel pBtn where i put 6 buttons that will decide which circles and lines are supposed to be drawn, the other JPanel, pDraw, is the panel where im drawing the circles and lines, this panel is inside a JScrollPane, so in case the image is too large it would allow to scroll left-right and up-down to view the full image, but when i tested it (i tested it drawing an oval with a size of width=500 and height=750) the scrollbars didnt work, here i put my code:
so if anyone can help me see my error i would be so glad, the complete program will be drawing bigger structures, im planning to save different structures of circles and lines drawn and then connect them, but that i'll do it later, first i wanna know what's the error im making with the scrollbars.Code:import javax.swing.*;
import javax.swing.event.MouseInputAdapter;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class AFNGUI extends JFrame implements ActionListener{
JButton btns[];
JPanel pBtn, pDraw;
JScrollPane sDraw;
public AFNGUI(){
getContentPane().setLayout(null);
setVisible(true);
setSize(650,550);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
btns=new JButton[6];
pBtn=new JPanel();
pBtn.setLayout(null);
pBtn.setSize(600,50);
pBtn.setAlignmentY(Component.TOP_ALIGNMENT);
for(int i=0;i<6;i++){
btns[i]=new JButton(new ImageIcon(i + ".PNG"));
btns[i].setName("" + i );
btns[i].setBounds(100*(i),0,50,50);
btns[i].setVisible(true);
pBtn.add(btns[i]);
}
btns[0].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {boton1(e);}
});
pBtn.setBorder(BorderFactory.createLineBorder(Color.black));
getContentPane().add(pBtn);
pDraw=new JPanel();
pDraw.setLayout(null);
pDraw.setBackground(Color.white);
pDraw.setSize(1000,1000);
sDraw=new JScrollPane(pDraw,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
sDraw.setBounds(0,50,600,450);
getContentPane().add(sDraw);
repaint();
}
public void boton1(ActionEvent e){
int w=500,h=750;
//pDraw.setSize(w,h);
Graphics g=pDraw.getGraphics();
g.setColor(Color.blue);
g.drawOval(100,150,w,h);
}
public void actionPerformed(ActionEvent e){}
public static void main(String args[]){
AFNGUI miafn=new AFNGUI();
}
}
thanks

