• Post Reply Bookmark Topic Watch Topic
  • New Topic

Component Titled Border  RSS feed

 
Michelle Streeter
Ranch Hand
Posts: 120
Eclipse IDE Flex Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been trying to create a customized border which I can pass a JComponent and location to the class and the class creates a border with the component inline with the border in the location given. Locations such as top left, bottom left, top right, bottom right. Several of the components I want to pass is a JLabel or a JCheckbox. on the JLabel, we also want to display an icon to identify the type of data which the border contains. I also need to add RichHelp to which ever component is passed to the border class.

Here is the parent code which is using FormLayout. Creating a JLabel and assigning an icon and then calling the component border



Now, I have several version of the code which kind of work but under some circumstances but not all circumstances. For instance, in one instance of code, the parent form is using FormLayout with constraints. And when I call the class to create the border, the component wont paint naturally, I have to trick it to paint by creating a window and adding the component to that window to get it to paint and then dispose of the window. Here is the code where I am doing this. I got this as a work around to a bug which evidently is filed. This code allows the JLabel to display and the icon to display but the help wont work. and the checkbox does not work. Evidently the component is not visible or showing.



I have another instance which you pass the parent panel to the code and so I dont need to trick the JComponent to paint and the checkbox does work. However, it fails because inside the border class, the formlayouts constraints from the parent panel are not visible and so it fails. Here is the code for displaying this. It appears as if the Swing Utilities is what is not getting the FormLayouts constraints. Also, I can access the checkbox but the help fails and says it fails because the component is not visible. also this is where I got the code for this instance Component Panel Border



Here is the code which I am attaching the help to the component. Here it is in the parent class. But I have tried to add the help to the component inside the border class and it didnt matter which place I put it.



I prefer the code which uses Paint to display the component, icon, and help and I do not need to pass the parent container. But how to get the component to be showing so it will paint, can be selected. And can display the help has avoided me. Any Suggestions?
 
Rob Camick
Ranch Hand
Posts: 2801
15
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Component Border might help you out.
 
Michelle Streeter
Ranch Hand
Posts: 120
Eclipse IDE Flex Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob, thank you for your reply. My question is a little more advanced than the link you provided. I am doing a little more than putting up a label. I am interacting with the component on the border. I can get some interaction if I use a panel but it interferes with the FormLayout manager. But if I do not use a panel, then the paint function skips it and has to be tricked to paint the component. But since it was tricked, its still not "showing" And so I can not interact with it. So I need someone who really knows there "Graphics" and Paint to help get this component it is painted and showing so I can interact with it.
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michelle Streeter wrote: So I need someone who really knows there "Graphics" and Paint to help get this component it is painted and showing so I can interact with it.


You are unlikely to find anyone in this forum with more Swing expertise than Rob ! Why don't you explain in general terms what you are trying to achieve (your current explanation does not do that for me) and then maybe someone can suggest a solution that does not involve the contortions you seem to be going through.
 
Rob Camick
Ranch Hand
Posts: 2801
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am doing a little more than putting up a label. I am interacting with the component on the border.


So does that code. I showed an example of adding a button to the border. Did you try the WebStart demo? Must admit I have tried it with a panel, but I don't see why it would be any different.

then the paint function skips it and has to be tricked to paint the component


My code uses a real component, not a rendered image of a component which is why it should react normally to Swing events.
 
Michelle Streeter
Ranch Hand
Posts: 120
Eclipse IDE Flex Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, using a panel allows the component, in this case a check box to display and you can interact with it. However, as stated above, the parent panel is using FormLayout with Constraints. the border panel is not the same as the parent panel where the border is set. And where the actual components the border will surround exist. And so the constraints are not visible and causes failure. I have already tried several versions of how to implement ComponentTitledBorder. But none of them work in this case.

Here are some of the examples I have tried so far.

http://www.java2s.com/Code/Java/Swing-Components/ComponentTitledPaneExample2.htm
This one shows promise but when I remove it from a frame to just a panel, it so far has not been working. Its the latest I have been working on. Got a higher priority task and so will hopefully get back to this one.

http://www.javalobby.org/java/forums/t33048.html
this one uses a panel but fails due to the FormLayout Constraints

There is another link which I was unable to find again, Its similar to the first link but does not use a panel. It works fine for just a static label but does not work for a checkbox. Hence the visible statements.
That one is the one the company I am doing work for has right now. But they wanted me to add the functionality of using a checkbox. At least it doesnt care about the FormLayout and its constraints because it does not use a panel or pane.

When I was researching on why the label was not showing, I ran accross this link


https://www.java.net//node/651276

This explained why the component was not being painted. And I am sure its why the same component is not being seen to interact with. But I was hoping someone might know of another work around. Or even a better work around than the one suggested in this link.
 
Michelle Streeter
Ranch Hand
Posts: 120
Eclipse IDE Flex Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is one assumption here. The code I am trying to come up with needs to be used in multiple scenarios. Not just one. It needs to be reusable.
 
Michelle Streeter
Ranch Hand
Posts: 120
Eclipse IDE Flex Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob, is your app capable of putting the component in line with the border?
 
Michelle Streeter
Ranch Hand
Posts: 120
Eclipse IDE Flex Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob, here is a main I created just to see how yours works. Not even testing FormLayout issues. And your border didnt even show up




 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!