Rendering JRadio Buttons and JLabels in the same column

I am using JTable for showing one to many relationship like shown below.
Column A Column B
x              1
x              3
y              5
y              7

I am allowing user to must select one of x y. In x also he can select any combination (like x 1 or x 2). So I thought to have column A as radio buttons as x in one radio button group, y in other radio button group.
But I will be using x 1, x3 in one radio button and for empty text in column A (e.g. I am not displaying x for x 2, not displaying x for x 4) I want to use JLabel.
So column A will be mix and match of radio buttons and JLables.
How that can be achieved with given customized JTable model?
Who is Participating?
zzynxSoftware engineerCommented:
By using your own TableCellRenderer you can show whatever you want.
But, I doubt if your solution is the right one.
I even doubt if I have understood you, well ;°)

Q: why don't you have this?

Column A Column B
x              1
y              5

Why do you want to repeat the x sometimes and sometimes not?
j74Author Commented:
I am creating parts mapping and saving to the database.
Suppose part A is mapped to the part B and Part C.
Some other user may have concern for mapping of A.
So he can create another mapping of A with part X and part Y or just part X.
So we need to store this mapping to against this user.
There may be same scenario happening for some other part say P.
So if the third user comes and for his scenario if part A and P comes, he may be shown that already Part A and Part P mapping exist. Select either of one for Part A and either of one for Part P.
This is kind of one to many relationship of part conversions and also you need to provide selection of different mapping for given part.
So for displaying the feature I am going for JTable with RadioButton and JLabel.
Part A is mapped Part B and Part C
Part A is also mapped with Part X and Part Y by other user.
Same may happen for Part P.
I thought I should provide like this:
I have 3 more columns (converting part qunatity, converted part quantity, otherfeaturedcolumn)

Part A  Part B
          Part C
PartA  Part X
          Part Y  
Part P  Part P1
          Part P2
Part P Part P3
         Part  P4  
I have seen various examples for Cell Rendering, but nothing suits to me.
This has has shown that we can
have any component in any cell but it lacks structured usage of Table Model

Let me know your thought about above mentioned scenario and sample.
Do we have other better way to show above mappings with easy business usage?
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

If the daa maintained by your model is proper formated, the cell renderer/editor of the B column must be a trivial JPanel, which will store your custom buttons and labels. Nothing has to e changed from the default way of rendering cells as described by most of tutorials.

Please see this site for the JTable rendering examples :
Following the link posted by myself, will lead the owner of this question to the right answer and much more on JTable customization techniques.
zzynxSoftware engineerCommented:
My first comment was:
>> By using your own TableCellRenderer you can show whatever you want.
And in my opinion - although rather common - that deserves some points too.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.