• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2973
  • Last Modified:

Add radio-button in JTable

Hi All,

I have added a JTable in a Panel. I have written below piece of code for it. I have two queries:

1) Using the below set of code, the application doesnot shows me the header part, columnNames, although it is displaying the data properly. I suppose i am missing some point here. Please comment!

JTable jAddInstanceTable ;
    Object[] columnNames = {
        "Select",
        " Name",
        "String Value",
        "String Password",
        " Comments"};
    Object[][] data = {
        {
        "radio-button", "iName", "value", "password", "comments"}
        , {
        "radio-button0", "iName0", "value0", "password0", "comments0"}
        , {
        "r1", "iName1", "value1", "password1", "comments1"}
    };

    jAddInstanceTable = new JTable(data,columnNames);
    JTableHeader th = new JTableHeader();
    th.setName("InstanceVector");
    jAddInstanceTable.setTableHeader(th);

2) I need to add radio button inside one of the row. and at one time only one radio button should be selectable. Any comments how to proceed for the same?

Thanks,
rdh
0
rohitdivas
Asked:
rohitdivas
  • 9
  • 7
  • 6
1 Solution
 
CEHJCommented:
1. You need to add the table to a JScrollPane

2. Please say more about how the radio buttons are to be distributed
0
 
zzynxSoftware engineerCommented:
1) Remove
>>  jAddInstanceTable.setTableHeader(th);
0
 
zzynxSoftware engineerCommented:
>> 1. You need to add the table to a JScrollPane
And that too
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rohitdivasAuthor Commented:
Regarding radiobutton, i need to display a radio button in first column of every row. And at one time user can select only one radio button
I am not getting the desired result even after deleting following lines from the code:
 JTableHeader th = new JTableHeader();
    th.setName("InstanceVector");
    jAddInstanceTable.setTableHeader(th);

rdh
0
 
zzynxSoftware engineerCommented:
>> I am not getting the desired result
Did you
>> add the table to a JScrollPane
?
0
 
zzynxSoftware engineerCommented:
>> Regarding radiobutton, i need to display a radio button in first column of every row.
>> And at one time user can select only one radio button
Then have a look at
http://www.objects.com.au/java/examples/swing/RadioButtonTableCell1.do
The code for this is (also) at :
http://www.physci.org/codes/display.jsp?fl=%2Fcodes%2Ftame%2Ftame%2Fexamples%2FJRadioButtonTableExample.java
0
 
CEHJCommented:
Adding to a scroll pane as i suggested is necessary

>>and at one time user can select only one radio button

That's going to take a special table model, where the values 'cut across' rows. You'll need a custom renderer to show the radio buttons
0
 
zzynxSoftware engineerCommented:
Thank you
0
 
CEHJCommented:
rohitdivas can you tell me why the answer i gave you was ignored please?
0
 
rohitdivasAuthor Commented:
Hi CEHJ,

Actually i was looking for a complete solutions for both of my queries. You had answered my first query right. But zzynx gave me complete answer.

But thanks a lot CEHJ for helping. Also, I am not ignoring your answer at all.

Regards,
RDH
0
 
CEHJCommented:
>>Actually i was looking for a complete solutions for both of my queries. You had answered my first query right.

Then i should have been credited for it.
0
 
rohitdivasAuthor Commented:
For me query a) had 10% weightage and query b) had 90% weightage.
So i.e 5 points for anwering ur query. Rather giving u 5 points , its better to give all 50 points to zzynx.

But, still lots of thanks!!

Do not worry CEHJ, next time, i shall definately consider this situation while assigning points.
RDH
0
 
CEHJCommented:
Blacklist++
0
 
zzynxSoftware engineerCommented:
rohitdivas, what about this proposal:
>> For me query a) had 10% weightage and query b) had 90% weightage.
Then you should have given the question a number of points that's in accordance of this weightage.
Since 20 points is the minimum to give in case of a split (10% = 20 points => 100% = 200 points)

You could
1) ask to reopen this question
2) once reopened, increment the points to 200
3) re-accept and split the points into 20/180
0
 
rohitdivasAuthor Commented:
But frankly telling, i do not wish to assign any more points on this query. What about proposal:
you transfer 5 points to CEHJ.
What do you say, CEHJ?
rdh
0
 
rohitdivasAuthor Commented:
>>Then you should have given the question a number of points that's in accordance of this weightage
Moreover if you look at the qureries, one can easily guess abt the weightage, it doesnot require any explicit mention.
rdh
0
 
CEHJCommented:
Forget it zzynx thanks, i simply shan't answer this person's questions again. I hope if you do, you don't happen to answer the 'wrong' part of the question correctly ;-)
0
 
rohitdivasAuthor Commented:
It's your wish CEHJ, no nody is forcing you to answer.

I liked zzynx quick, accurate and complete responses that is why I assigned him all the points.

I donot have any personal disliking for you, its just that i found zzynx more deserving.

rdh
0
 
zzynxSoftware engineerCommented:
>> I hope if you do, you don't happen to answer the 'wrong' part of the question correctly
As a matter of fact, rohitdivas, in the future you can avoid this kind of problems by following this EE rule:
Don't ask more than one question per 'thread'.
0
 
rohitdivasAuthor Commented:
Sure zzynx, anyways thanks for providing excellent, quality and timely answers
rohit
0
 
zzynxSoftware engineerCommented:
You're welcome
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 9
  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now