Drop_of_Rain
asked on
Change color on focus
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
}
}
}
}
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
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
}
}
}
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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(Co lor.blue);
}
public void mouseClicked(MouseEvent e) {
YourPanel.setBackground(Co lor.red);
}
public void mouseExited(MouseEvent e) {
YourPanel.setBackground(Co lor.white) ;
}
});
Hope that helps . . .
Javatm
JPanel YourPanel = new JPanel();
YourPanel.addMouseListener
public void mouseEntered(MouseEvent e) {
YourPanel.setBackground(Co
}
public void mouseClicked(MouseEvent e) {
YourPanel.setBackground(Co
}
public void mouseExited(MouseEvent e) {
YourPanel.setBackground(Co
}
});
Hope that helps . . .
Javatm
ASKER
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?
My solution works for any panel's so you can try it and see the results.
ASKER
Thanks You guys are very active tonight, I will have to take advantage of this!
Sure, I'm pretty active today but your also fast and did saw my other solutions
on some of your questions.
on some of your questions.
ASKER
Yes I did that is why I made the comment!
Thanks
Thanks
ASKER
Thanks for the support