?
Solved

Change color on focus

Posted on 2004-04-02
11
Medium Priority
?
295 Views
Last Modified: 2010-03-31
Hello everyone out there, another question.

I realized I need to ask you questions so you have them to answer!


How can I get the Jpanels color to get set on focus




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

public class MyClass4 extends JPanel {
  JLabel jLabel1;  
 
  ArrayList myArrayList = new ArrayList();

// Constructor
public MyClass4() {

    setLayout(new GridLayout(0,3)); // Setting MY layout...

add(jLabel1);  jLabel1.setText("Defensive Moves"); setBackground(Color.white);

    looprow:
        for (int row=0; row<20; row++) {
            for(int col=0; col<3; col++) {
                int n=(20*col+row+1);
                if (n>50) break looprow;
                JCheckBox check = new JCheckBox("" + n);

            myArrayList.add(check);
add(check); // Adding it to ME
}
}
}
}
0
Comment
Question by:Drop_of_Rain
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 92

Assisted Solution

by:objects
objects earned 375 total points
ID: 10746539
Use a FocusListener that and set the colour in the focuseGained() method.
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10746564
Maybe you mean when the mouse pointer enters the the area of the JPanel! Add a class that implements the MouseListener interface to the JPanel, and you will receive MouseEvents like mouseEntered and mouseExited.
0
 
LVL 15

Accepted Solution

by:
Javatm earned 375 total points
ID: 10746572
Hi friend;

Here is something which will help :
http://java.sun.com/docs/books/tutorial/uiswing/events/focuslistener.html

Hope that helps . . .
Javatm
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 15

Expert Comment

by:Javatm
ID: 10746577
Here is what you do if its a mouse event :

  JPanel YourPanel = new JPanel();
 
  YourPanel.addMouseListener(new MouseAdapter() {
  public void mouseEntered(MouseEvent e) {
  YourPanel.setBackground(Color.blue);
  }
  public void mouseClicked(MouseEvent e) {
  YourPanel.setBackground(Color.red);
  }
  public void mouseExited(MouseEvent e) {
  YourPanel.setBackground(Color.white);
  }
  });

Hope that helps . . .
Javatm
0
 

Author Comment

by:Drop_of_Rain
ID: 10746579
I will have about 12 JPanels with checkboxs with different colors. What do you think would be the best approach to help the user deal with all the checkbox groupings?
0
 
LVL 15

Expert Comment

by:Javatm
ID: 10746596
My solution works for any panel's so you can try it and see the results.
0
 

Author Comment

by:Drop_of_Rain
ID: 10746608
Thanks You guys are very active tonight, I will have to take advantage of this!
0
 
LVL 15

Expert Comment

by:Javatm
ID: 10746616
Sure, I'm pretty active today but your also fast and did saw my other solutions
on some of your questions.
0
 

Author Comment

by:Drop_of_Rain
ID: 10746655
Yes I did that is why I made the comment!

Thanks
0
 

Author Comment

by:Drop_of_Rain
ID: 10961239
Thanks for the support
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question