I am creating a button and label in JPanel. This panel i am adding to a JScrollPane which is eventually added to a frame. Here is my code.
public static void main(String[] args) {
final JFrame frame = new JFrame();
JPanel Jpanel =new JPanel(new GridLayout(0, 1));
JScrollPane pane = new JScrollPane(Jpanel,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
frame.setSize(500, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel n = new JLabel("hifadfad");
n.setBounds(90, 20, 100, 100);
Jpanel.add(n);
JButton b = new JButton("hi");
b.setBounds(10, 40, 60, 60);
Jpanel.add(b);
frame.add(pane);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
frame.setVisible(true);
}
});
}
After i run, i get something like this
How should i set the size of this button ?
Thanks for the help. Appreciate :)