Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4410243

JTextArea within JScrollPane using the GridBagLayout will flicker

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 1.3.0, 5.0
    • Fix Version/s: None
    • Component/s: client-libs
    • Subcomponent:
    • Understanding:
      Fix Understood
    • CPU:
      x86
    • OS:
      solaris_8, windows_nt

      Description

      Name: ssT124754 Date: 01/31/2001


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      1. STEPS TO REPRODUCE:

      A. Compile below source code
      B. Run app
      C. You should notice that the JTextArea within the JScrollPane is flickering.
      If you enlarge the JFrame to the point the scroll bar goes away, the flicker
      stops.

      D. If the setWrapStyleWord(true) in the TextComp class is commented out the
      flicker does not happen. But this implementation needs to break at the word
      boundary.


      Why is the flickering happening?


      2. SOURCE CODE:

      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;

      public class app extends JFrame {
      JTextField t_name;

      GridBagLayout gridbag;
      GridBagConstraints gc;

          JPanel mainPropertyPanel;
          JPanel settingsPropertyPanel;

      private GridBagLayout gbMainPropertyPanel;
      private GridBagConstraints gbcMainPropertyPanel;

      private GridBagLayout gbSettingsPropertyPanel;
      private GridBagConstraints gbcSettingsPropertyPanel;


          public app() {
              super("Flicking ScrollBar");

      gridbag = new
      GridBagLayout();
      gc = new
      GridBagConstraints();

      getContentPane().setLayout(gridbag);

      gc.fill = GridBagConstraints.BOTH;
      gc.insets = new Insets(3,3,1,3);
      gc.weightx = 1.0;
      gc.weighty = 0;
      gc.gridwidth = GridBagConstraints.REMAINDER;
      gc.gridy = GridBagConstraints.RELATIVE;

      t_name = new JTextField("Caption1");
      t_name.setBorder(BorderFactory.createLineBorder(Color.black));
      t_name.setFont(new Font("Dialog",Font.PLAIN,10));
      gridbag.setConstraints(t_name, gc);
      t_name.setHorizontalAlignment(SwingConstants.CENTER);
      getContentPane().add(t_name);

      gbMainPropertyPanel = new GridBagLayout();
      gbcMainPropertyPanel = new GridBagConstraints();

      mainPropertyPanel = new JPanel();
      gc.insets = new Insets(1,
      3, 1, 3);
      gc.weightx = 0;
      gc.weighty = 1;
      gc.gridwidth =
      GridBagConstraints.VERTICAL;
      gc.fill =
      GridBagConstraints.VERTICAL;
      gc.anchor =
      GridBagConstraints.WEST;
      gridbag.setConstraints(mainPropertyPanel, gc);

      mainPropertyPanel.setLayout(gbMainPropertyPanel);
      getContentPane().add(mainPropertyPanel);

      gbSettingsPropertyPanel = new GridBagLayout();
      gbcSettingsPropertyPanel = new GridBagConstraints();

      settingsPropertyPanel = new JPanel();
      gc.insets = new Insets(1,
      3, 1, 3);
      gc.weightx = 0;
      gc.weighty = 1;
      gc.gridwidth =
      GridBagConstraints.REMAINDER;
      gc.fill =
      GridBagConstraints.NONE;
      gc.anchor =
      GridBagConstraints.NORTHEAST;
      gridbag.setConstraints(settingsPropertyPanel, gc);

      settingsPropertyPanel.setLayout(gbSettingsPropertyPanel);
      getContentPane().add(settingsPropertyPanel);

      EntryObj entryObj = new EntryObj();
      mainPropertyPanel.add(entryObj);

      positionEntryObj(mainPropertyPanel, entryObj);

      EntryObj entryObj1 = new EntryObj();
      mainPropertyPanel.add(entryObj1);

      positionEntryObj(mainPropertyPanel, entryObj1);

          }

      public void positionEntryObj(JComponent objArea, EntryObj entryObj) {

      if ( objArea.equals(mainPropertyPanel) ) {
      gbcMainPropertyPanel.weighty = 1;

      gbcMainPropertyPanel.gridheight =
      GridBagConstraints.REMAINDER;
      gbcMainPropertyPanel.fill
      = GridBagConstraints.BOTH;
      gbcMainPropertyPanel.anchor =
      GridBagConstraints.SOUTH;
      gbMainPropertyPanel.setConstraints(entryObj,
      gbcMainPropertyPanel);
      mainPropertyPanel.revalidate();
      }
      else
      if ( objArea.equals(settingsPropertyPanel) ) {

      gbcSettingsPropertyPanel.gridwidth =
      GridBagConstraints.REMAINDER;
      gbcSettingsPropertyPanel.anchor =
      GridBagConstraints.EAST;
      gbSettingsPropertyPanel.setConstraints
      (entryObj, gbcSettingsPropertyPanel);

      settingsPropertyPanel.revalidate();
      }
      }


          public static void main(String args[]){
              final JFrame jFrame = new app();

              jFrame.setBounds(100, 100, 300, 140);
              jFrame.setVisible(true);
          }

      public void processWindowEvent(WindowEvent e){

      if ( e.getID() == WindowEvent.WINDOW_CLOSING ){
      dispose();
      System.exit(0);
      }

      super.processWindowEvent(e);
      }
      }

      import javax.swing.*;

      class TextComp extends JTextArea {

      public TextComp() {
      setWrapStyleWord(true);
              setLineWrap(true);
      setColumns(4);

      setText("this is a test. this is a test. test is test");
      }
      }

      import javax.swing.*;
      import java.awt.*;

      class EntryObj extends JPanel {
      private TextComp t_vocabulary;
      private JTextField t_selection;
      private JTextField t_hotkey;
      private JScrollPane vocabularyScrollPane;
      private GridBagLayout gb;
      private GridBagConstraints gbc;

      public EntryObj() {

      gb = new GridBagLayout();
      gbc = new GridBagConstraints();
      setLayout(gb);

      t_selection = new JTextField();

      t_vocabulary = new TextComp();
      vocabularyScrollPane = new JScrollPane(t_vocabulary);


      gbc.weighty = 1;
      gbc.gridheight = 1;
      gbc.gridy = 0;
      gbc.fill = GridBagConstraints.BOTH;
      gbc.anchor = GridBagConstraints.WEST;
      add(vocabularyScrollPane, gbc);

      t_hotkey = new JTextField("HK");

      t_hotkey.setFont(new Font("Dialog",Font.PLAIN,9));
      t_hotkey.setEditable(false);
      t_hotkey.setEnabled(false);
      t_hotkey.setDisabledTextColor(Color.black);
      t_hotkey.setHorizontalAlignment(SwingConstants.CENTER);

      gbc.weighty = 0;
      gbc.gridy = 1;
      gbc.fill =
      GridBagConstraints.BOTH;
      gbc.anchor =
      GridBagConstraints.WEST;
      add(t_hotkey, gbc);

      t_selection.setHorizontalAlignment(SwingConstants.CENTER);
              t_selection.setBorder(BorderFactory.createLineBorder(Color.black));

      gbc.weighty = 0;
      gbc.gridy = 2;
      gbc.fill =
      GridBagConstraints.BOTH;
      gbc.anchor =
      GridBagConstraints.WEST;
      add(t_selection, gbc);

      validateTree();
      }
      }
      (Review ID: 116062)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              peterz Peter Zhelezniakov
              Reporter:
              ssultanasunw Shaheen Sultana (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Imported:
                Indexed: