Forums.Sureshkumar.net : A Perfect Place to Share Knowledge         Blogs     Games    Magazines    

"Sharing knowledge does not lessen your store, often it gets you more. Sharing plays a key role in relationships and bonding, happens in small steps and is assisted through community membership."

Go Back   SURESHKUMAR.NET FORUMS > TECHNICAL DISCUSSIONS > JAVA Technologies
Register FAQ Members List Calendar Games Blogs Search Today's Posts Mark Forums Read

   

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
Old 23-02-07, 12:07 PM   #1 (permalink)
Member
 
Join Date: Jan 2007
Age: 27
Posts: 83
Thanks: 1
Thanked 2 Times in 2 Posts
Thanks: 1
Thanked 2 Times in 2 Posts
Rep Power: 2 kkchaitanya_18 is on a distinguished road
applet swing

import java.awt.Component;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.DefaultCellEditor;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import java.util.Random;
import java.math.*;
public class JRadioButtonTable extends JFrame {
public JRadioButtonTable() {
super("JRadioButtonTable Example");
DefaultTableModel dm = new DefaultTableModel();
dm.setDataVector(new Object[][] { { "1", new Integer(-1) },
{ "2", new Integer(-1) }, { "3", new Integer(0) },
{ "4", new Integer(1) }, { "5", new Integer(2) },{"6",new Integer(3)} ,{"7",new Integer(4)}}, new Object[] { "Question", "Answer" });
JTable table = new JTable(dm);
String[] answer = { "A", "B", "C","D" ,"E"};
table.getColumn("Answer").setCellRenderer(new RadioButtonRenderer(answer));
table.getColumn("Answer").setCellEditor(new RadioButtonEditor(new JCheckBox(), new RadioButtonPanel(answer)));
JScrollPane scroll = new JScrollPane(table);
getContentPane().add(scroll);
}
// Cell base
class RadioButtonPanel extends JPanel {
JRadioButton[] buttons;

RadioButtonPanel(String[] str) {
setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
buttons = new JRadioButton[str.length];
for (int i =0; i < buttons.length; i++)
{
buttons[i] = new JRadioButton(str[i]);
buttons[i].setFocusPainted(false);
add(buttons[i]);
}
}
public void setSelectedIndex(int index) {
for (int i = 0; i < buttons.length; i++) {
buttons[i].setSelected(i == index);
}
}
public int getSelectedIndex() {
for (int i = 0; i < buttons.length; i++) {
if (buttons[i].isSelected()) {
return i;
}
}
return -1;
}
public JRadioButton[] getButtons() {
return buttons;
}
}
class RadioButtonRenderer extends RadioButtonPanel implements
TableCellRenderer {
RadioButtonRenderer(String[] strs) {
super(strs);
}
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row,
int column) {
if (value instanceof Integer) {
setSelectedIndex(((Integer) value).intValue());
}
return this;
}
}
class RadioButtonEditor extends DefaultCellEditor implements ItemListener {
RadioButtonPanel panel;
public RadioButtonEditor(JCheckBox checkBox, RadioButtonPanel panel) {
super(checkBox);
this.panel = panel;
ButtonGroup buttonGroup = new ButtonGroup();
JRadioButton[] buttons = panel.getButtons();
for (int i = 0; i < buttons.length; i++) {
buttonGroup.add(buttons[i]);
buttons[i].addItemListener(this);
}
}
public Component getTableCellEditorComponent(JTable table,
Object value, boolean isSelected, int row, int column) {
if (value instanceof Integer) {
panel.setSelectedIndex(((Integer) value).intValue());
}
return panel;
}
public Object getCellEditorValue() {
return new Integer(panel.getSelectedIndex());
}
public void itemStateChanged(ItemEvent e) {
super.fireEditingStopped();
}
}
public static void main(String[] args) {
JRadioButtonTable frame = new JRadioButtonTable();
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)

{
System.exit(0);
}
});
frame.setSize(230, 140);
frame.setVisible(true);
}
}


In this code how I can make horizontal options to vertical
please give any one Idea.
kkchaitanya_18 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 27-02-07, 07:31 PM   #2 (permalink)
Member
 
Join Date: Sep 2006
Posts: 40
Thanks: 0
Thanked 4 Times in 3 Posts
Thanks: 0
Thanked 4 Times in 3 Posts
Rep Power: 5 muralipn has a spectacular aura about muralipn has a spectacular aura about muralipn has a spectacular aura about
Re: applet swing

Hi Chaitanya,

Please elobrate your question and the requirment.

Regards,
Murali
muralipn is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
java swing qaisar JAVA Technologies 3 28-03-07 07:25 PM
Position Vacant Java Swing / AWT Developer sridhar EXPERIENCED JOBS 0 22-02-07 04:07 PM
Java Swing Tutorial Unregistered JAVA Technologies 0 05-10-06 02:02 AM
Jawa Swing Programmer, NCY, NY sridhar EXPERIENCED JOBS 0 01-06-06 04:20 AM
CA vista Other Queries 2 14-04-06 02:49 AM


All times are GMT +6.5. The time now is 02:09 PM.





Search Engine Optimization by vBSEO 3.1.0