Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. JScrollPane sp = new JScrollPane(pt);
  2. fr.getContentPane().add(sp);
  3.  
  4. TextArea textArea = new JTextArea(40, 60);
  5. JScrollPane scrollableTextArea = new JScrollPane(textArea);
  6. scrollableTextArea.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
  7.  
  8. /*
  9. * To change this license header, choose License Headers in Project Properties.
  10. * To change this template file, choose Tools | Templates
  11. * and open the template in the editor.
  12. */
  13. package letc;
  14.  
  15. import javax.swing.*;
  16. import java.awt.*;
  17. import java.awt.event.*;
  18. import java.awt.BorderLayout;
  19. import java.awt.Color;
  20. import java.awt.Component;
  21. import java.awt.Dimension;
  22. import java.awt.FlowLayout;
  23. import java.awt.event.ActionListener;
  24. import java.awt.event.ActionEvent;
  25. import javax.swing.JFrame;
  26. import javax.swing.JTextField;
  27. import javax.swing.JPasswordField;
  28. import javax.swing.JOptionPane;
  29. import javax.swing.JLabel;
  30. import javax.swing.JPanel;
  31. import javax.swing.SwingUtilities;
  32. import javax.swing.JButton;
  33. import javax.swing.JComboBox;
  34.  
  35. public class Letc {
  36.  
  37. public static void main(String[] args) {
  38.  
  39. JFrame fr = new JFrame();
  40. JPanel p = new JPanel();
  41. p.setBackground(Color.blue);
  42.  
  43. JTextField tf = new JTextField(8);
  44. JTextArea pt = new JTextArea();
  45. pt.setLineWrap(true);
  46. pt.setWrapStyleWord(true);
  47.  
  48. tf.setBounds(20,80,100,40);
  49. pt.setBounds(200,20,400,400);
  50.  
  51. JScrollPane sp = new JScrollPane(pt);
  52. fr.getContentPane().add(sp);
  53. // I used the above code snippet to add scrollbar in the textarea but it's not working :(
  54.  
  55. JButton b= new JButton("click");
  56. b.setBounds(20,20,100,50);
  57.  
  58. b.addActionListener(new ActionListener() {
  59. @Override
  60. public void actionPerformed(ActionEvent e) {
  61. String st= tf.getText(),ck="";
  62. if(st.equals("")) {
  63. JOptionPane.showMessageDialog(null,"enter the length:");
  64. }
  65. else {
  66. int val=Integer.valueOf(st);
  67. String z="";
  68. for(int i=0;i<10000;i++) {
  69. z+='a';
  70. }
  71. pt.setText(z);
  72. }
  73. }
  74. });
  75.  
  76. fr.add(sp);
  77. fr.add(tf);
  78. fr.add(pt);
  79. fr.add(b);
  80. fr.add(p);
  81. fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  82. fr.setSize(600, 600);
  83. fr.setVisible(true);
  84. }
  85. }
  86.  
  87. p.add(sp);
  88. p.add(tf);
  89. p.add(pt);
  90. p.add(b);
  91. p.add(p);
  92. fr.add(p);
  93. fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  94. fr.setSize(600, 600);
  95. fr.setVisible(true);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement