Solved

Rendering JRadio Buttons and JLabels in the same column

Posted on 2004-10-21
460 Views
Last Modified: 2008-01-09
I am using JTable for showing one to many relationship like shown below.
Column A Column B
x              1
                2
x              3
                4
y              5
                6
y              7
                8

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?
0
Question by:j74
    6 Comments
     
    LVL 37

    Accepted Solution

    by:
    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
                    2
                    3
                    4
    y              5
                    6
                   7
                    8

    Why do you want to repeat the x sometimes and sometimes not?
    0
     
    LVL 5

    Expert Comment

    by:JK2429
    0
     

    Author Comment

    by:j74
    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 http://www.codeguru.com/java/articles/162.shtml 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?
    0
     
    LVL 9

    Assisted Solution

    by:Ovi
    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 :

    http://www.objects.com.au/java/examples.do
    0
     
    LVL 9

    Expert Comment

    by:Ovi
    Following the link posted by myself, will lead the owner of this question to the right answer and much more on JTable customization techniques.
    0
     
    LVL 37

    Expert Comment

    by:zzynx
    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.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: Foundations of Front-End Development

    Jump-start a lucrative career in front-end web development, with zero previous coding experience required. This course covers the basic programming concepts and languages required for creating engaging websites from scratch.

    1. Package the applet into a JAR file. The applet must be in a JAR file before a certificate can be attached to it. Use the jar JDK utility. If the applet was previously referenced with the help of a codebase attribute in  tag, replace the codebase …
    Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
    Video by: Michael
    Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
    Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

    933 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now