JScrollPane w/ JTextArea problems

I've written a simple terminal for a project I'm working on, with a JTextField for inputs and a JTextArea to display outputs. The JTextArea uses a JScrollPane to let it scroll vertically, and wraps text to avoid horizontal scrolling.
My problem is this: when I append text to the text area, the scroll pane sometimes scrolls to the bottom, sometimes scrolls part-way, and sometimes doesn't move at all. Ideally, I'd like to have the scroll pane always pushed to the bottom. Does anyone know what causes this kind of behaviour? What input causes the bar to scroll, and what input doesn't?
thanks,
Andrew

I don't know what causes the kind if behaviour you described, but this is how you get the scrollPane to scroll to the bottom:
int bottom = scrollPane.getVerticalScrollBar().getMaximum();
scrollPane.getVerticalScrollBar().setValue(bottom);

Similar Messages

  • Set Font to the JTextArea Problem

    Hi all, i've got a problem in setting the font for my JTextArea.
    Here is my piece of code.
    Display.append(Message.getText());
    Display.setFont(selected_font));
    Display is JTextArea, Message is String.
    The problem is i whenever i do this, everytime i change the Font of the Message, the whole messages in the Display font also change.
    What i want is, when i change the font of certain message, that certain message font ( instead of all message) also change in the Display.
    I know the problem is because of the Display.setFont(), it set the font for the whole content inside the Display. Any help to fulfill what i want?

    I'm not sure a JTextArea is appropriate for what you're doing. As its API documentation begins by saying "A JTextArea is a multi-line area that displays plain text. "
    You can set the font used by this component: but the point is that it uses a single font.
    Perhaps you are looking for a JEditorPane (including JTextPane). Check out Sun's tutorial for code examples etc: http://java.sun.com/docs/books/tutorial/uiswing/components/text.html

  • InputVerifier for JTextArea problem

    Hello,
    I am having a problem with using an InputVerifier to check a max character limit on a JTextArea. It seems that occasionally after the verify of the JTextArea fails, I lose the next character I type into it! Here is the code, followed by a description of how to reproduce the problem. Note this code is copied from the Java 1.4.2 API documentation of the InputVerifier class, with the first JTextField changed to a JTextArea and the verify method modified:
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.Frame;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.awt.event.WindowListener;
    import javax.swing.InputVerifier;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    public class TestJTextArea  extends JFrame {
        public TestJTextArea () {
           JTextArea ta = new JTextArea ("");
           ta.setPreferredSize(new Dimension(100, 50));
           getContentPane().add (ta, BorderLayout.NORTH);
           ta.setInputVerifier(new PassVerifier());
           JTextField tf2 = new JTextField ("TextField2");
           getContentPane().add (tf2, BorderLayout.SOUTH);
           WindowListener l = new WindowAdapter() {
               public void windowClosing(WindowEvent e) {
                   System.exit(0);
           addWindowListener(l);
        class PassVerifier extends InputVerifier {
            public boolean verify(JComponent input) {
                JTextArea jText = (JTextArea)input;
                boolean retValue = jText.getText().length() < 5;
                if (!retValue) {
                    System.out.println("MAX CHARS");
                return retValue;
        public static void main(String[] args) {
            Frame f = new TestJTextArea ();
           f.pack();
           f.setVisible(true);
    }A way to reproduce the problem is type in the TextArea: "123455", then Ctrl+Tab and the verify will fail. Then backspace twice to delete the "55" and Ctrl+Tab to move to the TextField. Then Tab again to go back to the TextArea and type any charachter over than 5. About 80% of the time, the character that you type will be lost and not appear in the TextArea. It doesn't always happen, but if you try it a few times it will come up. Also, occasionally the backspace keystroke is also lost in the TextArea. Note this only happens when I use Tab. I am not able to reproduce it by using the mouse to change focus.
    I have searched for a bug report on this, but have found nothing. Am I doing something wrong? I am simply using the sample code from the InputVerifier JavaDoc, but with a JTextArea... This is on a WinXP Pro machine with Java Std. Ed. 1.4.2.
    Thank you for your help.
    Angel

    JTextField jtf = (JTextField)comboBox.getEditor().getEditorComponent();
    jtf.setInputVerifier(new YourInputVerifier());

  • JTextArea problem

    Why does the following code not print "Test" in the JTextArea?
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.TextArea;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JPanel;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JComponent;
    import java.util.Collections;
    import java.util.LinkedList;
    import java.util.List;
    public class ImportServer extends JPanel implements ActionListener {
         protected JTextField textField;
         protected JTextArea textArea;
         private final static String newline = "\n";
         public ImportServer() {
              super(new GridBagLayout());
              textField = new JTextField(20);
              textField.addActionListener(this);
              textArea = new JTextArea(5, 20);
              textArea.setEditable(false);
              JScrollPane scrollPane = new JScrollPane(textArea,
              JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
              JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
              //Add Components to this panel.
              GridBagConstraints c = new GridBagConstraints();
              c.gridwidth = GridBagConstraints.REMAINDER;
              c.fill = GridBagConstraints.HORIZONTAL;
              add(textField, c);
              c.fill = GridBagConstraints.BOTH;
              c.weightx = 1.0;
              c.weighty = 1.0;
              add(scrollPane, c);
         public void actionPerformed(ActionEvent evt) {
              String text = textField.getText();
              textArea.append(text + newline);
              textField.selectAll();
              //Make sure the new text is visible, even if there
              //was a selection in the text area.
              textArea.setCaretPosition(textArea.getDocument().getLength());
         * Create the GUI and show it. For thread safety,
         * this method should be invoked from the
         * event-dispatching thread.
         private void createAndShowGUI() {
              //Make sure we have nice window decorations.
              JFrame.setDefaultLookAndFeelDecorated(false);
              //Create and set up the window.
              JFrame frame = new JFrame("Cbhk.net Import Server");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              //Create and set up the content pane.
              JComponent newContentPane = new ImportServer();
              newContentPane.setOpaque(true); //content panes must be opaque
              frame.setContentPane(newContentPane);
              //Display the window.
              frame.pack();
              frame.setSize(800,600);
              frame.setVisible(true);
         private void runImports() {
              textArea.append("Test\n");
              textArea.setCaretPosition(textArea.getDocument().getLength());
              textArea.repaint();
              textArea.validate();
              System.out.println(textArea.getText());
         public static void main(String[] args) {
              ImportServer server = new ImportServer();
              server.createAndShowGUI();
              server.runImports();

    in main, you create an instance of the ImportServer. In createAndShowGUI, you do it again. You are not working with the same instance as the one you see. Your text is appended to the textarea created in main, but you are looking at the one created in createAndShowGUI.
    Instead of creating a new ImportServer in the createAndShowGUI method, use 'this'.
    here is the updated version of createAndShowGUI:
    private void createAndShowGUI() {
         //Make sure we have nice window decorations.
         JFrame.setDefaultLookAndFeelDecorated(false);
         //Create and set up the window.
         JFrame frame = new JFrame("Cbhk.net Import Server");
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         //Create and set up the content pane.
         this.setOpaque(true); //content panes must be opaque
         frame.setContentPane(this);
         //Display the window.
         frame.pack();
         frame.setSize(800,600);
         frame.setVisible(true);

  • JScrollPane with JTextArea

    I'm creating a program where a user enters a string into a JTextField and then that string is appended to a new line in a JTextArea that is inside of a JScrollPane. I wanted to know how I could make it so that each time a line is appended to the JTextArea that the JScrollPane scrolls down to the bottom left, showing the new line? (If i don't touch the JScrollPane, this works on its own but after I scroll around it doesnt update the view to the bottom anymore).
    Thanks,
    swing can be a bit confusing at times.

    http://java.sun.com/docs/books/tutorialJWS/uiswing/components/ex6/TextDemo.jnlp
    http://java.sun.com/docs/books/tutorial/uiswing/components/textfield.html

  • Stop JScrollpane if JTextarea is full

    I've put a JTextArea with 27 rows on a JScrollpane with vertical scrollbar policy. And I want the JScrollPane to stop scrolling if the 27th row of the Textarea is full.
    But it scrolls and scrolls and adds further rows to the
    JTextArea... :-(
    Any idea???
    sicki

    Found a solution:
    Write your own Component. Inherit from JTextArea and override the createDefaultModel-Method.
    protected Document createDefaultModel() {
    return new LimitedDocument();
    static class LimitedDocument extends PlainDocument {
    // Begrenzung dieses Dokumentes (also der TextAreas):
    static final int LIMIT = 10;
    public void insertString(int offs, String str, AttributeSet a)
    throws BadLocationException {
    if (str != null) {
    if (offs < LIMIT) {
    super.insertString(offs, str, a);
    else {
    // Falls keine Zeichen mehr eingegeben werden d�rfen, wird gepiepst.
    Toolkit.getDefaultToolkit().beep();
    }

  • Scrollable JTextArea problem. Tried the techniques of previous posts.

    Hi guys,
    I know this is a very common post on this forum. I have tried the solutions mentioned in previos posts, but somehow I am unable to make a JTextArea Scrollable.
    I have written the following code :
              TAlab1 = new JTextArea(temp);
              TAlab1.setBounds(50, 130, 530, 50);
              TAlab1.setBorder(BorderFactory.createEtchedBorder() );
              TAlab1.setLineWrap(true);
              TAlab1.setEditable(false);
              jsp = new JScrollPane(TAlab1);
              p.add(jsp); // where p is JPanelHere, if I add jsp, then the JTextArea is not visible. If I add TAlab1, then I get a JTextArea, but which is not scrollable.
    I would appreciate any of your assistance.
    Regards
    kbhatia

    Calling setBounds can get you in trouble. Hardcoding values is almost always a bad idea. Here's a short demo of adding a JTextArea to a JScrollPane;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class ScrollTest extends JFrame{
        private String longString = "This is just a long string to be added over and over again to textarea\n";
        int times = 0;
        private JTextArea textArea;
        public ScrollTest() {
            buildGUI();
        private void buildGUI(){
            JPanel mainPanel = (JPanel) getContentPane();
            mainPanel.setLayout(new BorderLayout());
            JPanel centerPanel = buildCenterPanel();
            mainPanel.add(centerPanel, BorderLayout.CENTER);
            JPanel buttonPanel = buildButtonPanel();
            mainPanel.add(buttonPanel, BorderLayout.SOUTH);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            pack();
            setLocationRelativeTo(null);
            setVisible(true);
        private JPanel buildButtonPanel() {
            JPanel retPanel = new JPanel();
            JButton addButton  = new JButton("Add Text");
            addButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    addText();
            retPanel.add(addButton);
            return retPanel;
        private void addText() {
            textArea.append(times+ " "+longString);
            times +=1;
        private JPanel buildCenterPanel() {
            JPanel retPanel = new JPanel(new GridLayout(1,0, 5,5));
            textArea = new JTextArea(5,10);
            textArea.setWrapStyleWord(true);
            textArea.setLineWrap(true);
            textArea.setEditable(false);
            textArea.setEnabled(false);
            JScrollPane jsp = new JScrollPane(textArea);
            retPanel.add(jsp);
            return retPanel;
        public static void main(String[] args) {
            new ScrollTest();
    }Cheers
    DB

  • JTextArea problem: mouseClicked event irregular

    My application allows user to add several CalcArea objects (a subclass of JPanel) in a big JPanel. Highlight of ClassArea class is given below.
    Strangely, I find that once in a while, mouseClicked event is not fired. It is very critical for my user to select a particular CalcArea and modify/update the currently selected CalcArea. It is very much annoying to find that the mouseClicked event occurs irregularly. Please advise me how I can make sure mouseClicked event occurs when user clicks on the desired CalcArea. Thanks.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.math.*;
    import javax.swing.border.*;
    import java.awt.print.*;
    public class CalcArea extends JPanel implements MouseListener, FocusListener
       JTextArea ta;
       DrawPanel dp; //subclass of JPanel
       static int iCount=0;
       static int selectedMemberID=-1;
       int memberID;     //unique ID (0-based)
       //constructor
       public CalcArea(String strID....)
       }  //constructor ends
       public void mousePressed(MouseEvent e)
       } //method mousePressed ends
       public void mouseClicked(MouseEvent e)  //***Problem here
         selectedMemberID= memberID;
         System.out.print("mseClicked***");
       public void mouseReleased(MouseEvent e) {}
       public void mouseEntered(MouseEvent e) {}
       public void mouseExited(MouseEvent e) {}

    Is there any way to solve it? I don't really understand what you are trying to accomplish, but maybe somthing like the following will help:
    e.getComponent().getGraphics();
    e.getComponent().getParent().getGraphics();

  • JTable, JScrollPane, and JinternalFrame problems.

    I have this internal frame in my application that has a scrollpane and table in it. Some how it won't let me selelct anything in the table. Also it scrolls really weird. There's a lot of chopping going on. Here's my code for the internal frame:
    public class BCDEObjectWindow extends javax.swing.JInternalFrame{
        private Vector bcdeObjects = new Vector();
        private DefaultTableModel tModel;
        public BCDEObjectWindow(JavaDrawApp p) {
            initComponents();
            this.setMaximizable(false);
            this.setClosable(false);
            this.setIconifiable(true);
            this.setDoubleBuffered(true);
            objectTable.setPreferredScrollableViewportSize(new Dimension(500, 70));
            listScrollPane.setColumnHeaderView(new ObjectWindowHeader());
            pack();
            this.setVisible(true);
            parent = p;
            getAllBCDEFigures();
            setPopupMenu();
            tModel = (DefaultTableModel) objectTable.getModel();
            objectTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        public void getAllBCDEFigures() {
            bcdeObjects.removeAllElements();
            int i;
            for (i = 0; i < bcdeObjects.size(); i++) {
                tModel.removeRow(0);
        public void addBCDEFigure(BCDEFigure b) {
            bcdeObjects.add(b);
            tModel.addRow(new Object[]{b.BCDEName, "incomplete"});
        public void changeLabelName(BCDEFigure b) {
            if (bcdeObjects.contains(b)) {
                int index = bcdeObjects.indexOf(b);
                tModel.removeRow(index);
                tModel.insertRow(index, new Object[]{b.BCDEName, "incomplete"});
        public void removeBCDEFigure(BCDEFigure b) {
            int index = 0;
            if (bcdeObjects.contains(b)) {
                index = bcdeObjects.indexOf(b);
                bcdeObjects.remove(b);
                tModel.removeRow(index);
        public void removeAllBCDEFigures(){
            int i;
            for (i = 0; i < bcdeObjects.size(); i++) {
                tModel.removeRow(0);
            bcdeObjects.removeAllElements();
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
        private void initComponents() {
            jPanel1 = new javax.swing.JPanel();
            listScrollPane = new javax.swing.JScrollPane();
            objectTable = new javax.swing.JTable();
            getContentPane().setLayout(new java.awt.FlowLayout());
            setBackground(new java.awt.Color(255, 255, 255));
            setIconifiable(true);
            setTitle("BCDE Objects");
            listScrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            listScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
            listScrollPane.setPreferredSize(new java.awt.Dimension(250, 150));
            objectTable.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][] {
                new String [] {
                    "Name", "Status"
                boolean[] canEdit = new boolean [] {
                    true, false
                public boolean isCellEditable(int rowIndex, int columnIndex) {
                    return canEdit [columnIndex];
            objectTable.setColumnSelectionAllowed(true);
            listScrollPane.setViewportView(objectTable);
            jPanel1.add(listScrollPane);
            getContentPane().add(jPanel1);
            pack();
        }// </editor-fold>
        // Variables declaration - do not modify
        private javax.swing.JPanel jPanel1;
        private javax.swing.JScrollPane listScrollPane;
        private javax.swing.JTable objectTable;
        // End of variables declaration
    }and this is how i create the object in my JFrame:
    bcdeOW = new BCDEObjectWindow(this);
            bcdeOW.setLocation(400, 0);
            if (getDesktop() instanceof JDesktopPane) {
                ((JDesktopPane)getDesktop()).setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
                ((JDesktopPane)getDesktop()).add(bcdeOW, JLayeredPane.PALETTE_LAYER);
            } else
                getDesktop().add(bcdeOW);Any help would be great. Thanks a lot.

    Rajb1 wrote:
    to get the table name to appear
    create a scollpane and put the table in the scrollpane and then add the the scollpane to the component:
    //declare
    scrollpane x;
    //body code
    scrollpane x - new scrollpane();
    table y = new table();
    getContentPane().add(x(y));What language is this in, the lambda calculus -- add(x(y))!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • JTable in JPanel in JTabbedPane in JScrollPane in JSplitPane problem

    I have a JSplitPane with a divider in the center; of which the top is a JPanel and the bottom is a JScrollPane that contains a JTabbedPane, for which each tab contains a JPanel which contains a JTable.
    When I move the divider up, so that it now takes up 75% of the JSplitPane, the JScrollPane and the JTabbedPane expand with the JSplitPane, but the JPanel that contains the JTable remains the same size that it had at the beginning.
    What I would like to see is more rows of the JTable as I move the divider to give the JScrollPane more room.
    Is there an easy way to keep all of the J components sizes in sync as the JSplitPane gets larger or smaller ? (JDK 1.3.1)

    Hi,
    The JPanels which you have inside each tab of the JTabbedPanes should have BorderLayout and the JScrollPanes which hold the JTables should be added with the BorderLayout.CENTER constraint. This will make sure that the JScrollPanes that contain the JTables occupy as much space as possible.
    Hope this helps,
    Ranga.

  • Scrolling JTextArea Problems

    Hi,
    I have created a simulator based on Pattis's Karel the Robot, in Swing, which has two "logging" JTextArea's. During execution of a main method that runs the simulator the logs append new entries, and the scroll pane that they are contained within changes the viewport position so that the last entry is always shown. The caret is also adjusted so that it is located at the last appended or selected entry. However during execution I often get Null Pointer Exceptions or Array Index out Of Bounds exceptions (non-fatal) relating to the PlainView class in the JDK - and they always seem related to the refresh of dirty components. I am sure it is related to the constant scrolling of the JTextArea's but I may be wrong about that ....I was just wondering if you have any suggestions on what I can do about this or what may be the possible source.
    Thanks
    Master Sifo-Dyas

    It seems that I have found an answer in the archived Swing forum (how did I not see it before?).
    It seems that after appending a message I should use the line:
    textArea.setCaretPosition(textArea.getText().length());
    to move the caret to the end of the text, which updates the scrolling automatically.
    I tried it and it seems to work.

  • JTextArea within a JScrollPane within a JSplitPane

    public class CamoDataGUI
         JScrollPane primaryPane;
         JTextArea infoTextArea;
         public CamoDataGUI()
              infoTextArea = new JTextArea("Information", 10,10);
              primaryPane = new JScrollPane(infoTextArea);
         public JScrollPane getContent()
              return primaryPane;
    }Its simply not visible. getContent() is being used to provide one of the values for the SplitPane constructor that asks for an orientation and a left and right component.
    any ideas as to why its MIA?
    Thanks!

    I would like to apologize before anyone responds. I added the wrong class into the constructor of my splitpane.

  • HTML TextArea is a  JScrollPane in JEditorPane?

    Hi all,
    I'm trying to create an autofill facility for my application, to do this I am getting the components from the HTML document and converting them to their Java Swing counterpart.
    So for example <input type="text" name="example" /> would be a normal text input field on a HTML form, and its Swing conversion is a JTextField - this works as desired and it allows me to use the .settext() command to set the text on the HTML form - i.e. autofilling.
    My problem comes when I try to get the component for a HTML textarea, e.g. <textarea name="example"></textarea> - I would expect the Swing component to be a JTextArea, but the class it gets converted to is a JSrcollPane! This leads to a problem as I can't set the text of a JScrollPane as it is a container.
    Does anyone know how I might get around this problem so that I can set the text for the textarea? I've included my code below.
    Many thanks
    BBB
    import java.awt.event.*;
    import java.awt.*;
    import java.net.URL;
    import javax.swing.*;
    public class Tester extends JFrame{
        static JEditorPane pane = new JEditorPane();
        public Tester()
            try {
                pane.setPage( new URL("http://www.amray.com/cgi/amray/addurl.cgi") );
            } catch (Exception e) {
            this.getContentPane().add(new JScrollPane(pane));
            JButton b1 = new JButton("Auto Fill");
            this.getContentPane().add(b1,BorderLayout.SOUTH);
            b1.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e)
                    for ( int i = 0; i < pane.getComponentCount(); i++ )
                        Container c = (Container)pane.getComponent(i);
                        Component swingComponentOfHTMLInputType = c.getComponent(0);
                        System.out.println(swingComponentOfHTMLInputType.getClass());
                        if ( swingComponentOfHTMLInputType instanceof JTextField ) {
                            JTextField tf = (JTextField)swingComponentOfHTMLInputType;
                            tf.setBackground( Color.yellow );
                            tf.setText("Auto Filled");
                        if ( swingComponentOfHTMLInputType instanceof JScrollPane ) {
                            JScrollPane ta = (JScrollPane)swingComponentOfHTMLInputType;
        public static void main(String args[]) {
            Tester app = new Tester();
            app.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
            app.setSize( 400, 400 );
            app.setVisible( true );
    }

    Hi Jim,
    Thanks for the suggestion, but I've already tried that and although it does work from a visual POV, when you then submit the form the data in the JTextArea isn't added - it just says the field is blank.
    Although, I'm not sure whether it's not working due to the method I've had to use to add the JTextArea: -
    JScrollPane ta = (JScrollPane)swingComponentOfHTMLInputType;
    JTextArea oTextArea = new JTextArea();
    oTextArea.setText("Hello World!");
    ta.setViewportView(oTextArea);I'm not sure if it's not working because I've had to use .setViewportView(); rather than .add(). If I use .add() then no changes are reflected on screen and the JTextArea isn't actually added.
    Any other suggestions?

  • Help!! how to access JTextArea in JScrolPane inside JTabbedPane

    hi there my problem is i want to access setFont method of JTextArea inside JScrolPane which is also inside a JTabbedPane
    here is my code in creating new tabPane:
    if(e.getSource() == createNewTabButton){
    //instance variable editorTab = new JTabbedPane
    editorTab.addTab("Title", new JScrollPane( new JTextArea(18,51) );
    how do i use this code to set the font for every JTextArea in every Tab:
    editorTab.getSelectedComponent()./* i dont know what goes here* /.setFont(new Font(....));
    thanks..

    hi there my problem is i want to access setFont
    method of JTextArea inside JScrolPane which is also
    inside a JTabbedPane
    here is my code in creating new tabPane:
    if(e.getSource() == createNewTabButton){
    //instance variable editorTab = new JTabbedPane
    ditorTab.addTab("Title", new JScrollPane( new
    JTextArea(18,51) );
    how do i use this code to set the font for every
    JTextArea in every Tab:
    editorTab.getSelectedComponent()./* i dont know
    what goes here* /.setFont(new Font(....));
    thanks..This is the only way i could get it to work....
    UIManager.put("TextArea.font", new Font("Trebuchet MS", Font.PLAIN, 32));//overrides the look and feel properties or something
    SwingUtilities.updateComponentTreeUI(editorTab.getSelectedComponent());  //this takes your selected component and applies your font settings to it

  • Setting focus to a JTextArea using tab

    Hi,
    I have a JPanel with a lot of controls on it. When I press tab I want to
    move focus to the next focusable component. This works fine for
    JTextFields, but when the next component is a JTextArea in a
    JScrollPane then I have to press tab 3 times to set the focus to the
    JTextArea. After pressing the tab key once I think the focus is set to
    the scrollBars of the JTextArea because when I press the up and down
    arrows the textarea is scrolled.
    How can I stop the JScrollPane from getting the focus?
    I have tried to set focusable to false on the scrollPane:
    scrollPanel.setFocusable(false);
    and the scrollBars of the scrollPane:
    scrollPanel.getHorizontalScrollBar().setFocusable(false);
    scrollPanel.getVerticalScrollBar().setFocusable(false);
    But it dosen�t work. Is this a completely wrong way of doing it?
    Please help!
    I use jdk 1.4.1
    :-)Lisa

    Not sure what your problem is. The default behaviour is for focus to go directly to the JTextArea.
    import java.awt.*;
    import javax.swing.*;
    public class Test1 extends JFrame
         public Test1()
              getContentPane().add( new JTextField("focus is here"), BorderLayout.NORTH );
              getContentPane().add( new JButton("Button1") );
              getContentPane().add( new JScrollPane( new JTextArea(5, 30) ), BorderLayout.SOUTH );
         public static void main(String[] args)
              Test1 frame = new Test1();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setVisible(true);
    }

Maybe you are looking for

  • Audio not recognized

    When I insert a audio-cd in my MATSHITADVD-R UJ-825 drive, Finder reports that it cannot read this cd. But the drive is working ok, because Toast Titanium can recognize the audio-cd en shows all the content. The problem only is with audio-cd's, data-

  • In Solution Landscape Application Servers are not displaying

    Dear All, We are integrated SOLMAN (7.0 Ehp1) server with R/3 Dev,Qua,Prd servers but in DSWP >Operations>Solution Monitoring-->System monitoring / Administration .We can see the Dev,Qua,Prd servers but our requirement is under Dev server we have 4 a

  • Workspace Startup Option shows only None

    Hi All, I have just installed epm 11.1.2.3. We are using Foundation, Planning, Essbase and Workspace only. After the successful configuration, in Workspace, under Manage Preferences and within the Default Startup Options drop down box i can see only

  • How come I cant accept terms?

    my terms and conditions continue to loop as I try to accept them. this happens on my computer and my iPad. please help. I can't download any games.

  • Cannot get sound to go through earphones

    plug them in and sound / music is played from phon'es speaker, not earphones.