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

Visual bug when using JTextField and setBackground color on toolbar.

    XMLWordPrintable

    Details

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10


      A DESCRIPTION OF THE PROBLEM :
      When using textfield in toolbar with .setBackground color set graphical glitch appears displaying other components and when changing input character.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run program, enter text of different characters into text field.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Cleared text field with no graphical glitches.
      ACTUAL -
      Show elements of other components on frame and corrupted characters.

      ---------- BEGIN SOURCE ----------
      package app;

      public class App {

          public static void main(String[] args) {
              Overview ov = new Overview();
          }
          
      }

      package app;

      import java.awt.BorderLayout;
      import java.awt.Color;
      import java.awt.Dimension;
      import java.awt.Font;
      import javax.swing.BorderFactory;
      import javax.swing.ImageIcon;
      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.JMenu;
      import javax.swing.JMenuBar;
      import javax.swing.JMenuItem;
      import javax.swing.JPanel;
      import javax.swing.JScrollBar;
      import javax.swing.JTextArea;
      import javax.swing.JTextField;
      import javax.swing.JToolBar;
      import javax.swing.border.Border;

      public class Overview {

          //create frame
          JFrame myF = new JFrame();
          //create panel for menu
          JPanel menuP;
          JPanel editP;
          //create menu bar
          JMenuBar menuBar = new JMenuBar();
          //create file and edit menus
          JMenu fileMenu = new JMenu("File");
          JMenu editMenu = new JMenu("Edit");
          //items for file menu
          JMenuItem newItem = new JMenuItem("New");
          JMenuItem openItem = new JMenuItem("Open");
          JMenuItem saveItem = new JMenuItem("Save");
          JMenuItem saveAllItem = new JMenuItem("Save all");

          //items for edit menu
          JMenuItem undoItem = new JMenuItem("Undo");
          JMenuItem redoItem = new JMenuItem("Redo");

          JMenuItem cutItem = new JMenuItem("");
          JMenuItem copyItem = new JMenuItem("");
          JMenuItem pasteItem = new JMenuItem("");

          JMenuItem find = new JMenuItem("");

          //create toolbar
          JToolBar toolBar = new JToolBar();
          //create buttons for toolbar
          JButton newBtn = new JButton("new");
          JButton openBtn = new JButton("open");
          JButton saveBtn = new JButton("Save");
          JButton saveAllBtn = new JButton("Save all");
          JButton findBtn = new JButton("Search");
          JTextField findField = new JTextField();

          ImageIcon newIcon = new ImageIcon("images/new file.png");
          ImageIcon openIcon = new ImageIcon("images/open.png");
          ImageIcon saveIcon = new ImageIcon("images/save.png");
          ImageIcon saveAllIcon = new ImageIcon("images/save all.png");
          ImageIcon findIcon = new ImageIcon("images/find.png");

          JTextArea textArea = new JTextArea();
          JScrollBar scroll;

          //create empty borders to apply to buttons in the toolbar
          Border emptyBorder = BorderFactory.createEmptyBorder();

          Overview() {
              myF.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              myF.setSize(700, 400);
              myF.setVisible(true);

              menuP = new JPanel();
              editP = new JPanel();

              scroll = new JScrollBar();

              editP.add(textArea);

              myF.setJMenuBar(menuBar);

              menuBar.add(fileMenu);

              menuBar.add(editMenu);

              fileMenu.add(newItem);
              fileMenu.add(openItem);
              fileMenu.add(saveItem);
              fileMenu.add(saveAllItem);
              editMenu.add(undoItem);
              editMenu.add(redoItem);

              Dimension d = new Dimension(600, 50);
              toolBar.setPreferredSize(d);
              Dimension textD = new Dimension(600, 200);
              textArea.setPreferredSize(textD);

              toolBar.setBorder(emptyBorder);

              newBtn.setBorder(emptyBorder);
              openBtn.setBorder(emptyBorder);
              saveBtn.setBorder(emptyBorder);
              saveAllBtn.setBorder(emptyBorder);
              findField.setBorder(emptyBorder);
              findBtn.setBorder(emptyBorder);

              //remove focus for buttons
              newBtn.setFocusable(false);
              openBtn.setFocusable(false);
              saveBtn.setFocusable(false);
              saveAllBtn.setFocusable(false);
              findField.setBorder(emptyBorder);

              Font findFieldF = new Font("Arial", 0, 30);
              Font findBtnF = new Font("Arial", 0, 30);

              findField.setFont(findFieldF);
              findBtn.setFont(findBtnF);
              findField.setBackground(new Color(10, 200, 80, 12));
              findBtn.setBackground(new Color(5, 200, 80, 250));
              //set icons for buttons
              newBtn.setIcon(newIcon);
              openBtn.setIcon(openIcon);
              saveBtn.setIcon(saveIcon);
              saveAllBtn.setIcon(saveAllIcon);

              //add buttons to toolbars
              toolBar.add(newBtn);
              toolBar.add(openBtn);
              toolBar.add(saveBtn);
              toolBar.add(saveAllBtn);
              toolBar.add(findField);

              toolBar.add(findBtn);

              myF.add(menuP, BorderLayout.WEST);
              myF.add(editP, BorderLayout.SOUTH);
              menuP.add(toolBar);

          }

      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      remove .setBackground(new Color(10, 200, 70, 20); from code.


      FREQUENCY : always


        Attachments

        1. App.java
          0.1 kB
        2. Capture.PNG
          Capture.PNG
          17 kB
        3. Overview.java
          4 kB

          Activity

            People

            Assignee:
            rmahajan Rajat Mahajan
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: