Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- JScrollPane sp = new JScrollPane(pt);
- fr.getContentPane().add(sp);
- TextArea textArea = new JTextArea(40, 60);
- JScrollPane scrollableTextArea = new JScrollPane(textArea);
- scrollableTextArea.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package letc;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.awt.BorderLayout;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.FlowLayout;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import javax.swing.JFrame;
- import javax.swing.JTextField;
- import javax.swing.JPasswordField;
- import javax.swing.JOptionPane;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.SwingUtilities;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- public class Letc {
- public static void main(String[] args) {
- JFrame fr = new JFrame();
- JPanel p = new JPanel();
- p.setBackground(Color.blue);
- JTextField tf = new JTextField(8);
- JTextArea pt = new JTextArea();
- pt.setLineWrap(true);
- pt.setWrapStyleWord(true);
- tf.setBounds(20,80,100,40);
- pt.setBounds(200,20,400,400);
- JScrollPane sp = new JScrollPane(pt);
- fr.getContentPane().add(sp);
- // I used the above code snippet to add scrollbar in the textarea but it's not working :(
- JButton b= new JButton("click");
- b.setBounds(20,20,100,50);
- b.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- String st= tf.getText(),ck="";
- if(st.equals("")) {
- JOptionPane.showMessageDialog(null,"enter the length:");
- }
- else {
- int val=Integer.valueOf(st);
- String z="";
- for(int i=0;i<10000;i++) {
- z+='a';
- }
- pt.setText(z);
- }
- }
- });
- fr.add(sp);
- fr.add(tf);
- fr.add(pt);
- fr.add(b);
- fr.add(p);
- fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- fr.setSize(600, 600);
- fr.setVisible(true);
- }
- }
- p.add(sp);
- p.add(tf);
- p.add(pt);
- p.add(b);
- p.add(p);
- fr.add(p);
- fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- fr.setSize(600, 600);
- fr.setVisible(true);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement