473,320 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

change panels color on mouseover

Hi,
if somebody coud help me .
It`s a beginner`s question but I`ve tryed to solve it for three days.
I have several panels and I need to change their color when the
mouse is over them.
If someone has any ideas......
Thanks.
Dec 4 '06 #1
2 4201
r035198x
13,262 8TB
Hi,
if somebody coud help me .
It`s a beginner`s question but I`ve tryed to solve it for three days.
I have several panels and I need to change their color when the
mouse is over them.
If someone has any ideas......
Thanks.
Post the code you have so far so we have something to work with.
Dec 5 '06 #2
here is the code :

Expand|Select|Wrap|Line Numbers
  1. package myprojects.SokSzinesPanel;
  2. import java.awt.*;
  3. import javax.swing.*;
  4. import java.lang.*;
  5.  
  6. public class SokSzinesPanelFrame extends JFrame {
  7.  
  8.         public static void main(String args[])
  9.     {
  10.         SokSzinesPanelFrame win = new SokSzinesPanelFrame ();
  11.  
  12.         java.awt.EventQueue.invokeLater(new Runnable() {
  13.             public void run()
  14.             {
  15.                 new SokSzinesPanelFrame().setVisible(true);
  16.  
  17.             }
  18.         });
  19.     }
  20.  
  21.      public SokSzinesPanelFrame() {
  22.          super ("Ablak");
  23.          addMenus();
  24.          addComponents();
  25.         pack();
  26.          resize(400,400);
  27.          show();
  28.          }
  29.         void addMenus() {
  30.          MenuBar menubar = new MenuBar();
  31.          Menu file = new Menu("File");
  32.          file.add("Quit");
  33.          menubar.add(file);
  34.          setMenuBar(menubar);
  35.         }        
  36.  
  37.    void addComponents() {
  38.  
  39.         JPanel panel =new JPanel(); 
  40.         panel.setBackground(java.awt.Color.cyan);
  41.         setLayout(new GridLayout(2,1));
  42.         add("North",panel);
  43.         JPanel panel1 =new JPanel();
  44.         panel1.setBackground(java.awt.Color.green);
  45.         panel1.setSize(100,100);
  46.         add("South",panel1);
  47.         JPanel panel2 =new JPanel();
  48.         panel2.setBackground(java.awt.Color.magenta);
  49.         panel2.setSize(100,100);
  50.         add("Center",panel2);
  51.         JPanel panel3 =new JPanel();
  52.         panel3.setBackground(Color.orange);
  53.         panel3.setSize(100,100);
  54.         add("West",panel3);
  55.  
  56.  
  57.          addMouseListener(new MouseAdapter() {
  58.  
  59.  
  60.             public void mouseEntered(MouseEvent e)
  61.             {
  62.  
  63.                 Color c = new Color((float)Math.random(), (float)Math.random(), 
  64.                         (float)Math.random());
  65.  
  66.  
  67.                 getContentPane().setBackground(c);
  68.             }
  69.         });
  70.  
  71.  
  72.       }
  73.  
  74.  
  75.  
  76. /*public boolean handleEvent(Event event) {
  77.     if (event.id==Event.WINDOW_DESTROY){
  78.         System.exit(0);
  79.         return true;
  80.     }else if (event.id==Event.ACTION_EVENT &&
  81.        event.target instanceof MenuItem) {
  82.            if ("Quit".equals(event.arg)) {
  83.                System.exit(0);
  84.                return true;
  85.            }else{
  86.                return false;
  87.            }
  88.        }else if(event.id==Event.ACTION_EVENT &&
  89.             event.target instanceof Panel){
  90.                 return true;
  91.        }else return false;
  92. }*/
  93.  
  94.  
  95. }
  96.  
Dec 5 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: RWD | last post by:
I am trying to figure out how to change the target frame in my hyperlink on a DHTML menu. The menu is in one frame and the target frame is called "main" The code is below: Thanks in advance...
3
by: Wojciech Trelak | last post by:
Hi, Does anyone know how to change an owner of a control inherited from the base form? In code it's simple, but the real question is how to force designer to do this? Is it possible? I tried...
6
by: J.S. | last post by:
I have a TreeView control in the left panel of a SplitContainer. When I click on various nodes in the TreeView I would like different sets of buttons and textboxes to appear in the right panel. ...
3
by: Mel | last post by:
Hi, Is there any way I can force to change button background colour when toggle button is checked? Just like button change its background colour when mouseover in MS Visual Studio.NET. I hope I...
2
by: Amy | last post by:
<style> div.helpBtn{ font:bold 73% verdana; color:#995F8D; text-align:left; width:79px; height:24px; margin:0px; padding: 5px 0px 0px 27px; background:...
1
by: fritz21 | last post by:
Hi. I have a program which changes a frame`s background on mouseover. The problem is that I need several panels to change color on mouseover..... If somebody could help.,... Here is the code: ...
7
by: moondaddy | last post by:
in asp.net 2.0, i have a link buttonand want to change the forecolor in a mouse over event. how can I do this? -- moondaddy@noemail.noemail
0
by: spacecadet563 | last post by:
I am trying to change and display the image source of an image control (named image2 )on mouseover of cell event on a gridview(Gridview1) with a SQL datasource. The cell contains image name of image...
19
by: andersond | last post by:
I want the text to change from gray to bright red when the mouse is moved over the name of our company. Here is the code that doesn't work. What do I need to change to make this work? function...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.