Results 1 to 3 of 3
- 08-25-2010, 09:30 PM #1
Member
- Join Date
- Aug 2010
- Posts
- 2
- Rep Power
- 0
Why won't the scrollbar show up in a JTextArea?
I'm not sure what I'm doing wrong
Java Code:package com.tjffx.jNotes; import java.awt.Dimension; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; public class TextEditor extends JFrame { /** * jNotes Android Sync */ private static final long serialVersionUID = 1L; private Toolkit toolkit; public JTextField txt_test = new JTextField(); public JTextArea txt_editor = new JTextArea(10,20); JScrollPane scrollingpane = new JScrollPane(txt_editor, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); public static void setNativeLnF(){ //SET NATIVE LnF try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (UnsupportedLookAndFeelException e) { e.printStackTrace(); } } public static void main(String[] args){ setNativeLnF(); TextEditor win = new TextEditor(); win.setVisible(true); } public TextEditor(){ //SETUP WINDOW setTitle("jNotes"); setSize(300, 200); toolkit = getToolkit(); Dimension size = toolkit.getScreenSize(); setLocation((size.width - getWidth())/2, (size.height - getHeight())/2); setDefaultCloseOperation(EXIT_ON_CLOSE); //SETUP PANEL JPanel panel = new JPanel(); getContentPane().add(panel); panel.setLayout(null); //SETUP BUTTONS JButton beep = new JButton("Sync"); beep.setBounds(0, 0, 80, 20); beep.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { testFunction(); } }); //SETUP TEXTAREA txt_editor.setBounds(0,20,200,300); //ADD TO PANEL panel.add(beep); panel.add(txt_editor); panel.add(scrollingpane); } void testFunction(){ } }
-
You're adding the text component to both the JScrollPane and the JPanel, and so it will only display in one or the other, not both. You should add it to the JScrollPane and then add just the JScrollPane and not the text component to the main JPanel. Also, don't setBounds on the JTextArea but rather set the preferred size. In fact, you should set bounds on nothing here but instead learn to use the user-friendly layout managers.
- 08-25-2010, 10:50 PM #3
Member
- Join Date
- Aug 2010
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
how to show web browser in mobile app or is it possible to show it in textArea
By Basit781 in forum CLDC and MIDPReplies: 3Last Post: 05-27-2010, 10:54 AM -
JTextArea on PopUp -JTextArea isn't editable
By Richy76 in forum AWT / SwingReplies: 3Last Post: 02-01-2010, 07:51 PM -
How can I show my log class in jTextArea
By mtz1406 in forum AWT / SwingReplies: 4Last Post: 10-29-2009, 12:15 PM -
netbeans 6.0 not show commpunent or show blank page
By fahimaamir in forum NetBeansReplies: 1Last Post: 01-26-2008, 06:20 AM -
How to always show the last line in my JTextArea?
By Ashley in forum New To JavaReplies: 1Last Post: 05-26-2007, 01:01 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks