JDK-4154909 : JTextArea.setTabSize() does not work
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.0,1.3.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,windows_95,windows_nt
  • CPU: generic,x86
  • Submitted: 1998-07-06
  • Updated: 2002-08-12
  • Resolved: 2002-08-12
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.2 mantisFixed
Related Reports
Duplicate :  
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
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mantis FIXED IN: mantis INTEGRATED IN: mantis
14-06-2004

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. ======================================================================
11-06-2004

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; } } ======================================================================
11-06-2004