473,792 Members | 3,400 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

change panels color on mouseover

3 New Member
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 4259
r035198x
13,262 MVP
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
fritz21
3 New Member
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
5306
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 RWD <script type='text/javascript'>
3
2072
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 to play with the Component Designer Generated Code Best Regards
6
3082
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. Is this doable? Also, it seems that the TreeView nodes do not have a click event. Is that correct? Thanks, J.S.
3
10644
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 can get my question answered. Thank you very much.
2
4026
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: url(/jsp/images/pms/housekeeping/helpBtn_off.gif) no-repeat; } div.helpBtnOn{ font:bold 73% verdana; color:#BB59DE; text-align:left; width:79px; height:24px; margin:0px; padding: 5px 0px 0px 27px; background: url(/jsp/images/pms/housekeeping/helpBtn_on.gif) no-repeat; cursor:pointer; }...
1
1529
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: import java.awt.Color; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JFrame;
7
21822
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
1725
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 in web app directory. The VB code behind I started with is: Protected Sub Gridview1_RowDataBound If (e.Row.RowType = DataControlRowType.DataRow) Then Dim mytext As String = Server.HtmlDecode(e.Row.Cells(8).Text)...
19
16141
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 mouseOver(){ document.getElementById('unitedBrokers').style.font="size='2' face='Arial color='#FF0000'"; }// mouseOver() function mouseOut(){ document.getElementById('unitedBrokers').style.font="size='2' face='Arial color='#808080'"; }//...
0
9517
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10156
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9997
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9030
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4110
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.