United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4154909 : JTextArea.setTabSize() does not work

Details
Type:
Bug
Submit Date:
1998-07-06
Status:
Resolved
Updated Date:
2002-08-12
Project Name:
JDK
Resolved Date:
2002-08-12
Component:
client-libs
OS:
windows_nt,generic,windows_95
Sub-Component:
javax.swing
CPU:
x86,generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.2.0,1.3.0
Fixed Versions:
1.4.2 (mantis)

Related Reports
Duplicate:

Sub Tasks

Description
JTextArea.setTabSize() does not work.  Tabs are always expanded to eight
characters, no matter what value setTabSize() is invoked with.

To see this, bring up the following application, use the slider to set 
the tab size, then use the <TAB> key to check if the tab size has
changed.

=======================================================================
/*
 * JTextAreaTest.java
 * JTextArea.setTabSize() does not work
*/


import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
import com.sun.java.swing.event.*;

public class JTextAreaTest extends JFrame implements ChangeListener {
    JTextArea textarea;
    JSlider tabSize;
    JPanel infoPanel = new JPanel();
    JPanel p1 = new JPanel();
    JPanel p2 = new JPanel();

    public JTextAreaTest()    {
        Container c = getContentPane();
	c.setLayout(new BorderLayout());
	infoPanel.setLayout(new GridLayout(0,1));
        infoPanel.add(new JLabel("JTextArea.setTabSize() does not work."));
        infoPanel.add(new JLabel("Use slider to set tab size of textarea."));
        c.add(BorderLayout.NORTH, infoPanel);

        textarea = new JTextArea(10,40);

        p1.add(textarea); 
        c.add(BorderLayout.CENTER, p1);

        tabSize = new JSlider(JSlider.HORIZONTAL,0,40,20);
	tabSize.setMajorTickSpacing(8);
	tabSize.setMinorTickSpacing(1);
	tabSize.createStandardLabels(8);
	tabSize.setToolTipText("Invokes setTabSize().");
	tabSize.setPaintTicks(true);
	tabSize.setPaintLabels(true);
	tabSize.addChangeListener(this);
	tabSize.setValue(textarea.getTabSize());
        p2.add(new JLabel("Tab size: "));
        p2.add(tabSize);
        p2.setBackground(Color.pink); 

        c.add(BorderLayout.SOUTH, p2);
    }

    public static void main(String argv[])    {
        JFrame frame = new JTextAreaTest();
	frame.setTitle("JTextArea Test");
	frame.pack();
	frame.setSize(600,350);
	frame.setVisible(true);
    }

    public void stateChanged(ChangeEvent e)    {
	JSlider slider = (JSlider)e.getSource();
	int value = slider.getValue();

	System.out.println("Invoking setTabSize("+value+")...");
	textarea.setTabSize(value);
    }
}
=======================================================================

                                    

Comments
SUGGESTED FIX



Name: slR10134			Date: 05/24/2002




------- PlainView.java -------
*** /tmp/sccs.mUa4Pm	???? ?????? 24 19:07:09 2002
--- PlainView.java	???? ?????? 24 19:06:59 2002
***************
*** 183,193 ****
      protected void updateMetrics() {
  	Component host = getContainer();
  	Font f = host.getFont();
! 	if (font != f) {
  	    // The font changed, we need to recalculate the
  	    // longest line.
  	    calculateLongestLine();
! 	    tabSize = getTabSize() * metrics.charWidth('m');
  	}
      }
  
--- 183,197 ----
      protected void updateMetrics() {
  	Component host = getContainer();
  	Font f = host.getFont();
! 	int newTabSize = tabSize;
! 	if (metrics!= null) {
! 	    newTabSize = getTabSize() * metrics.charWidth('m');
! 	}
! 	if (font != f || newTabSize != tabSize) {
  	    // The font changed, we need to recalculate the
  	    // longest line.
  	    calculateLongestLine();
! 	    tabSize = newTabSize;
  	}
      }
  


======================================================================
                                     
2004-06-11
EVALUATION



Name: slR10134			Date: 05/24/2002



(###@###.###)

The reason of the bug is the following: to determine the position
of next tabs stop class PlainView (in method nextTabStop) uses 
variable tabSize. tabSize is recalculated in method updateMetrics
only when font has been changed. It causes that changing of tab size
is not taken into account.
The idea of the fix is to check (in method updateMetrics)
whether the tab size has been changed.

======================================================================
                                     
2004-06-11
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
mantis

FIXED IN:
mantis

INTEGRATED IN:
mantis


                                     
2004-06-14



Hardware and Software, Engineered to Work Together