Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, I\'m trying to get create a hover state for comboBox_3 . When the user ho

ID: 3904575 • Letter: H

Question

Hello,

I'm trying to get create a hover state for comboBox_3 . When the user hovers over it, Im trying to get it to scale up in height and length by 2 pixels. Below is the code.

import java.awt.EventQueue;

import javax.swing.JFrame;

import javax.swing.JComboBox;

import javax.swing.DefaultComboBoxModel;

import javax.swing.ImageIcon;

import javax.swing.JLabel;

import java.awt.Font;

import java.awt.Image;

import java.awt.SystemColor;

import javax.swing.UIManager;

import java.awt.Color;

import java.awt.Cursor;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

public class Main_GUI {

   private JFrame frmAaAutomation;

   /**

   * Launch the application.

   */

   public static void main(String[] args) {

       EventQueue.invokeLater(new Runnable() {

           public void run() {

               try {

                   Main_GUI window = new Main_GUI();

                   window.frmAaAutomation.setVisible(true);

               } catch (Exception e) {

                   e.printStackTrace();

               }

           }

       });

   }

   /**

   * Create the application.

   */

   public Main_GUI() {

       initialize();

   }

   /**

   * Initialize the contents of the frame.

   */

   private void initialize() {

       frmAaAutomation = new JFrame();

       frmAaAutomation.setTitle("All Access Automation");

       frmAaAutomation.getContentPane().setBackground(new Color(245, 245, 245));

       frmAaAutomation.setBounds(100, 100, 650, 900);

       frmAaAutomation.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

       frmAaAutomation.getContentPane().setLayout(null);

      

       JComboBox comboBox_3 = new JComboBox();

  

       comboBox_3.setName("DeviceDropD");

       comboBox_3.setBounds(148, 194, 343, 27);

       comboBox_3.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

       comboBox_3.setModel(new DefaultComboBoxModel(new String[] {"Desktop", "Mobile Web", "Tablet"}));

       frmAaAutomation.getContentPane().add(comboBox_3);

      

       comboBox_3.addMouseListener(new MouseAdapter() {

           public void mouseEntered(java.awt.event.MouseEvent evt) {

              comboBox_3.setBounds(158, 196, 355, 30);

              }

              public void mouseExited(java.awt.event.MouseEvent evt) {

              comboBox_3.setForeground(UIManager.getColor("GREEN"));

              }

       });

      

       JLabel lblCreateSettings = new JLabel("Create Test");

       lblCreateSettings.setBounds(193, 106, 250, 37);

       lblCreateSettings.setForeground(Color.GRAY);

       lblCreateSettings.setFont(new Font("Heiti TC", Font.PLAIN, 36));

       frmAaAutomation.getContentPane().add(lblCreateSettings);

   }

}

Explanation / Answer

============================

Try above code, it is working. You probably are forgetting to bring the height and width back to original in your mouseExited method.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote