Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

To draw cross line above JTable  RSS feed

 
Arun Chidam
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

wondering if someone help me on this requirement?

I need to draw a cross line with red color on top of JTable which should not effect the existing functionality of Jtable( i.e scrolling/editing/updating of table should be normal as before)

I thought about drawing a table from Graphics2D API and draw a cross line on top of table image , but that will make the table as static image and won;t respond to user input...

Is there any way around?....googled few sites but could not find much info....can anyone share your thoughts, any sample codes will be really helpful.

Thanks,
Arun

 
Rob Spoor
Sheriff
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about using a border to do the drawing? You'll need to implement javax.swing.border.Border, doing the painting in paintBorder, and returning an Insets object with 0 for the top, left and right and the height of the cross as the bottom. Then you set it like this:
 
Arun Chidam
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob,

Yes i will give it a try with your input and let you know the outcome.

Thanks,
Arun
 
Arun Chidam
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Rob,

I tried the below code and it worked fine as long i hard core the the x,y coordinates, if i try with table width and height it always returns zero, any idea?
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if i try with table width and height it always returns zero, any idea?

Not without seeing the code that did that.

edit Oh I see. You're trying to pass thewidth and height as parameters to the constructor. Don't do that.

Notice that the paintBorder(...) method has a parameter for the Component to be painted to. Can you guess why?
 
Arun Chidam
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Darryl Burke wrote:
Notice that the paintBorder(...) method has a parameter for the Component to be painted to. Can you guess why?


Hi Darryl,

As per Java API documentation the parameter component C is for which the border is being painted, so you are saying to use the component width and lenght on the paintborder method?

Thanks,
Arun
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What did you get when you tried it that way?
 
Arun Chidam
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:What did you get when you tried it that way?

It worked , thanks a lot Darryl

 
Rob Spoor
Sheriff
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's drawing a cross behind (or is it in front of?) the table, not above. You should use the x, y, w and h parameters.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe Arun used 'on top of' to mean 'in front of'
 
Arun Chidam
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:I believe Arun used 'on top of' to mean 'in front of'


Sorry for the confusion, yes it is "infront of Jtable".


 
Rob Spoor
Sheriff
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah ok, then I misunderstood the entire time...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!