Results 1 to 6 of 6
Thread: Java your Help please
- 12-22-2007, 07:19 PM #1
Member
- Join Date
- Dec 2007
- Posts
- 5
- Rep Power
- 0
Java your Help please
Hi All,
I am a new member in this Forum. I need your help please, I did a program n I have a problem in making the radio buttons,checkBox, and Buttons in columns.
I want it to be in this way:

And what I did appeared in this way :

Here is the code:
//GUIFrame.java
import java.awt.FlowLayout;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JTextField;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import javax.swing.JComboBox;
public class GUIFrame extends JFrame{
private JLabel label1,labelQuality;
private JList list1,list2,list3;
private JCheckBox checkBox1, checkBox2,checkBox3,checkBox4;
private JRadioButton radioButton1,radioButton2,radioButton3;
private JComboBox comboBox;
private JButton button1,button2,button3,button4;
private ButtonGroup radioGroup;
public GUIFrame(){
super("Printer");
setLayout(new FlowLayout());
label1=new JLabel("Printer: MyPrint");
label1.setVerticalTextPosition(SwingConstants.TOP) ;
label1.setHorizontalTextPosition(SwingConstants.LE FT);
add(label1);
Icon img1=new ImageIcon(getClass().getResource("1.gif"));
JLabel labelImg1=new JLabel(img1);
add(labelImg1);
checkBox1=new JCheckBox("Image");
add(checkBox1,BorderLayout.EAST);
checkBox2=new JCheckBox("Text");
add(checkBox2,BorderLayout.SOUTH);
checkBox3=new JCheckBox("Code");
add(checkBox3,BorderLayout.SOUTH);
Icon img2=new ImageIcon(getClass().getResource("2.gif"));
JLabel labelImg2=new JLabel(img2);
add(labelImg2);
radioButton1=new JRadioButton("Selection",false);
radioButton2=new JRadioButton("All",true);
radioButton3=new JRadioButton("Applet",false);
radioGroup=new ButtonGroup();
radioGroup.add(radioButton1);
add(radioButton1);
radioGroup.add(radioButton2);
add(radioButton2);
radioGroup.add(radioButton3);
add(radioButton3);
Icon img3=new ImageIcon(getClass().getResource("1.gif"));
JLabel labelImg3=new JLabel(img3);
add(labelImg3);
button1=new JButton("OK");
add(button1);
button2=new JButton("Cancel");
add(button2);
button3=new JButton("Setup...");
add(button3);
button4=new JButton("Help");
add(button4);
labelQuality=new JLabel("Printer Quality:");
labelQuality.setHorizontalAlignment(SwingConstants .LEFT);
labelQuality.setVerticalAlignment(SwingConstants.B OTTOM);
add(labelQuality);
String comboChoices[]={"High","Medium","Low"};
comboBox= new JComboBox(comboChoices);
comboBox.setMaximumRowCount(2);
add(comboBox);
checkBox4=new JCheckBox("Print to File");
add(checkBox4);
}
}
-------------------------------------------------------------------
//GUIFrameTest.java
import javax.swing.JFrame;
public class GUIFrameTest
{
public static void main(String args[]){
GUIFrame guiFrame=new GUIFrame();
guiFrame.setDefaultCloseOperation(JFrame.EXIT_ON_C LOSE);
guiFrame.setSize(600,400);
guiFrame.setVisible(true);
}
}Last edited by juju; 12-22-2007 at 07:23 PM.
- 12-23-2007, 01:15 AM #2
Member
- Join Date
- Dec 2007
- Posts
- 2
- Rep Power
- 0
Try a GridBagLayout. Have you ever used a Visual Editor. I use Eclipse and I like it alot.
- 12-27-2007, 07:23 AM #3
I'm not 100% sure, but isn't GroupLayout also a choice? In this code, I would visualize three main groups, maybe four... one for check boxes, one for radios and one for the column of button choices to the right.
- 12-28-2007, 03:23 AM #4
Member
- Join Date
- Dec 2007
- Posts
- 5
- Rep Power
- 0
Sorry for answering late...
Thanks alot both of you:) for helpin me...I downloaded some of the tutorial from the Internet and finally solved it using GridLayout..
Regarding Eclipse, I haven't ever used it but I think I should download it, I heared many Java programmers used it.
- 12-28-2007, 03:35 AM #5
Awesome, glad your problem was solved.
- 12-28-2007, 03:44 AM #6
Member
- Join Date
- Dec 2007
- Posts
- 5
- Rep Power
- 0


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks