-
JPanel class of java
Hello friend,
I am beginner in the field of advanced java programming. I am totally confused about the JPanel class of java programming language. I don't have any idea about the use of JPanel class. I have referred various websites for this but didn't get proper details. Do have enough knowledge about the JPanel class of java? If yes then please let me know that along with suitable example for it. I am waiting for your reply.
-
Re: JPanel class of java
Hi,
A JPanel class of java is also referred as lightweight container. A JPanel class basically implements MenuContainer, Serializable, Accessible, ImageObserver these interfaces. A JPanel class odd java is originally taken from the java package known as 'javax.swing.JComponent'. Thre are two subclasses are available with JPanel class and which are JSpinner.DefaultEditor & AbstractColorChooserPanel.
-
Re: JPanel class of java
Please refer following example of the JPanel class of java. In this example I uases isFocusCycleRoot() method of JPanel class:
Code:
import javax.swing.JPanel;
public class JPaneldm {
public static void main(String args[]) {
JFrame frame03 = new JFrame("Focus Cycle Sample");
Container contentPane = frame03.getContentPane();
contentPane.setLayout(new GridLayout(3,3));
for (int i = 0; i < 8; i++) {
JButton button02 = new JButton("" + i);
contentPane.add(button02);
}
JPanel panel01 = new FocusCycleConstrainedJPanel();
panel01.setLayout(new GridLayout(1, 3));
for (int i = 0; i < 3; i++) {
JButton button02 = new JButton("" + (i + 3));
panel01.add(button02);
}
contentPane.add(panel01);
frame03.setSize(400, 200);
frame03.setVisible(true);
}}
class FocusCycleConstrainedJPanel extends JPanel {
public boolean isFocusCycleRoot() {
return true;
}
}
-
Re: JPanel class of java
Hi friend,
Below are some method as well as the constructors of JPanel class of java. These methods and constructors are used to access the properties of JPanel class:
- JPanel(LayoutManager lyt, boolean DoubleBuffered)
- JPanel(LayoutManager lyt)
- JPanel()
- JPanel(boolean DoubleBuffered)
- setUI(PanelUI pui)
- getAccessibleContext()
- getUIClassID()
-
Re: JPanel class of java
Hello friend,
I suggets yout to study follwing example of JPanel class. This java example will show you the use of JPanel class:
Code:
import javax.swing.JPanel;
import javax.swing.JRadioButton;
public class JPdemo extends JPanel {
public MainClass() {
JRadioButton radMarriedYes1 = new JRadioButton("Yes?", true);
JRadioButton radMarriedNo1 = new JRadioButton("No?", false);
ButtonGroup radioGroup01 = new ButtonGroup();
setLayout(null);
add(radMarriedYes1);
add(radMarriedNo1);
radioGroup01.add(radMarriedYes1);
radioGroup01.add(radMarriedNo1);
radMarriedYes1.setBounds(40, 50, 50, 20);
radMarriedNo1.setBounds(40, 80, 50, 20);
}
public static void main(String[] args) {
JFrame frame2 = new JFrame();
frame2.getContentPane().add(new MainClass());
frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame2.setSize(200, 200);
frame2.setVisible(true);
}
}
Page generated in 1,750,909,598.45608 seconds with 10 queries