Доброго времени суток.
Подскажите пожалуйста, как мне добавить на мой фрейм JScrollBar, что бы при уменьшении размеров фрейма появлялись элементы прокрутки.
Код:
public class RGB
{
public static void main(String[] args)
{
ColorFrame color = new ColorFrame();
color.setVisible(true);
}
}
class ColorFrame extends JFrame
{
JButton but1 = new JButton("Set");
JTextField text1 = new JTextField();
JTextField text2 = new JTextField();
JTextField text3 = new JTextField();
public ColorFrame()
{
this.setTitle("RGB");
this.setBounds(50, 50, 250, 250);
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container cnt = getContentPane();
cnt.setLayout(null);
cnt.add(but1);
cnt.add(text1);
cnt.add(text2);
cnt.add(text3);
but1.setBounds(150, 100, 60, 20);
text1.setBounds(50, 50, 60, 20);
text2.setBounds(50, 100, 60, 20);
text3.setBounds(50, 150, 60, 20);
ColorAction col = new ColorAction(Color.red);
but1.addActionListener(col);
}
public class ColorAction implements ActionListener
{
public ColorAction(Color c)
{
backgroundColor = c;
}
private Color backgroundColor;
float R;
float G;
float B;
public void actionPerformed(ActionEvent ae)
{
try
{
if (ae.getSource() == but1)
{
String R1 = text1.getText();
R = Integer.parseInt(R1);
String G1 = text1.getText();
G = Integer.parseInt(G1);
String B1 = text1.getText();
B = Integer.parseInt(B1);
but1.getParent().setBackground(Color.getHSBColor(R, G, B));
}
}
catch(NumberFormatException e)
{
}
}
}
}