Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-22-2007, 08:19 PM
Member
 
Join Date: Dec 2007
Posts: 5
juju is on a distinguished road
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 08:23 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-23-2007, 02:15 AM
Member
 
Join Date: Dec 2007
Posts: 2
Hank Ag99 is on a distinguished road
Try a GridBagLayout. Have you ever used a Visual Editor. I use Eclipse and I like it alot.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-27-2007, 08:23 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 740
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
Quote:
Originally Posted by Hank Ag99 View Post
Try a GridBagLayout. Have you ever used a Visual Editor. I use Eclipse and I like it alot.
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.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-28-2007, 04:23 AM
Member
 
Join Date: Dec 2007
Posts: 5
juju is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 12-28-2007, 04:35 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 740
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
Awesome, glad your problem was solved.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 12-28-2007, 04:44 AM
Member
 
Join Date: Dec 2007
Posts: 5
juju is on a distinguished road
Thanks ..
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +3. The time now is 07:48 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org