List of usage examples for javax.swing JScrollPane JScrollPane
public JScrollPane(Component view, int vsbPolicy, int hsbPolicy)
JScrollPane
that displays the view component in a viewport whose view position can be controlled with a pair of scrollbars. From source file:Main.java
public static void main(String[] args) { JFrame window = new JFrame(); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setResizable(false);/*from w ww . j a v a2 s.co m*/ JTextArea textArea = new JTextArea(25, 30); JScrollPane textScroll = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); window.add(textScroll); window.pack(); window.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JTextPane codearea = new JTextPane(); JScrollPane scroll;/*from w w w .j a v a 2s . c o m*/ scroll = new JScrollPane(codearea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); scroll.setPreferredSize(new Dimension(300, 300)); JPanel panel = new JPanel(new BorderLayout()); panel.add(scroll, BorderLayout.CENTER); JButton comp = new JButton("Print text"); comp.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println(codearea.getText()); } }); panel.add(comp, BorderLayout.SOUTH); frame.getContentPane().add(panel); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
From source file:FlowLayoutTest.java
public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("FlowLayout Test"); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String text = "A JTextArea object represents" + "a multiline area for displaying text." + "You can change the number of lines" + "that can be displayed at a time."; JTextArea textArea1 = new JTextArea(text, 5, 10); textArea1.setPreferredSize(new Dimension(100, 100)); JTextArea textArea2 = new JTextArea(text, 5, 10); textArea2.setPreferredSize(new Dimension(100, 100)); JScrollPane scrollPane = new JScrollPane(textArea2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); textArea1.setLineWrap(true);// w w w . ja v a 2 s.co m textArea2.setLineWrap(true); frame.add(textArea1); frame.add(scrollPane); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String text = "A JTextArea object represents a multiline area for displaying text. " + "You can change the number of lines that can be displayed at a time, " + "as well as the number of columns. You can wrap lines and words too. " + "You can also put your JTextArea in a JScrollPane to make it scrollable."; JTextArea textAreal = new JTextArea(text, 5, 10); textAreal.setPreferredSize(new Dimension(100, 100)); JTextArea textArea2 = new JTextArea(text, 5, 10); textArea2.setPreferredSize(new Dimension(100, 100)); JScrollPane scrollPane = new JScrollPane(textArea2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); textAreal.setLineWrap(true);//from w ww . jav a 2s . c o m textArea2.setLineWrap(true); frame.add(textAreal); frame.add(scrollPane); frame.pack(); frame.setVisible(true); }