Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Java программирование > Общие вопросы по Java, Java SE, Kotlin
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 14.02.2011, 20:17   #1
grimm_jow
Пользователь
 
Регистрация: 27.01.2010
Сообщений: 25
Радость JScrollBar

Доброго времени суток.
Подскажите пожалуйста, как мне добавить на мой фрейм 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)
				{
				
				}
		}		
	}
}
grimm_jow вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц