Problem in obtaining the focus of JTable? - java

This is the scenario:
I have a JTable of nxn. In the Col(0) of each cell, have a slider with two thumbs each for min and max,two JTextField to represent min and max.
Whenever i click for first time on the cell, slider doesn't responds but on the second click the slider responds.
My guess is that on the first click the JTable gets the focus and on the second click the cell.
would like the cell to respond on the first click.
Thank you on advance...

set setClickCountToStart(1), more descriptions here

As I didn't see your code, I guess it's the FocusTraTraversalPolicy that is causing your problem.
In each container of Swing, the components have a predefined order of getting focus. They get the focus in order when you press the Tab button on the keyboard. So when you first click a container, there's a default component that gets the focus, if you're not satisfied with it, you can use the FocusTraversalPolicy to modify it.
Check this lnk out, it may help you.

Related

JCombobox drop-down list is not large enough to show all items

When I run the application and I click on the JCombobox for the first time, the drop-down list looks like this
The second time I click, it seems to rearrange everything and all items are shown.
Any idea why this may be happening?
I would appreciate your help.
SOLVED: I was adding the JComboBox instance to the panel before adding the items to the JComboBox.
Check the height property, may be it is collapsing with other component. Design and placement of the component should be correct in swing to behave properly.

make tab keyboard button jump from right to left

CASE:
create jpanel
add a few textbox horizontally
set panel to setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT)
PROBLEM:
when running, focus on one textbox and press tab button , the focus will jump from left to right , how do i make it jump from right to left?
FOLLOW UP:
say I want one component to be skipped, I can catch the on focus event for this component, but can i issue an automated additional tab click to jump to the next component ?
Thanks a lot for any help.
Check out FocusTraversalPolicy.
Here's an example.

SWT button position after resizing

I'm working with SWT. I created a button, and it supposed to change its text after being pressed.
The second text is wider than the first one, and the button does not being re-sized appropriately.
so I used button.pack(), and setSize() functions. The real issue is actually with its alignment in the shell after this size changing.
it's being expanded to the right instead to the left.
I guess it's actually the normal behavior, but I'm not sure where to change it.
I tried to change things by creating a gridData but it only did worse.
The button parent is tabFolder, and the last consists of a gridlayout with two uneven columns, the spesific button is on the second column.
I tried to change things with the margins and few others, but without success.
currently all the configurations are default.
This is my button:
This is how I would like it to behave:
any help would be highly appreciated.
many thanks!
i would need some code to be sure, but it looks like you need to call tabFolder.layout(true) after changing the button text to compute the new position of your button

Extending JXDatePicker for Time JComboBoxes

So I'm trying to extend the JXDatePicker to include a Time element. I have replaced the link panel at the bottom of the JXDatePicker pane with a couple of labels and a couple of drop down boxes (JComboBox), one for hour and one for minute. However, I can't seem to select anything from either box before the click listener closes the pane as if I have made a date selection. I don't want to completely override this listener, as I want to keep it closing when I pick a date, but I want to be able to populate the combo boxes before I do.
Does anyone know how I can stop this happening?
Thanks in advance.

How to make a mouseEvent from a Component to be recognized in a subcomponent?

I have a JTabPane, and i have added a MoustListener to it(for tab's title).
When i press right click, a popup menu is created.
i need to make it invisible when i press the mouse button in any place of window. how can i do this??
(the MouseListener is applied only for tab's title.)
i need to make it invisible when i
press the mouse button in any place of
window. how can i do this??
This is the default behavour of a JPopupMenu so you don't have to do anything special.
Read the JPopupMenu API and you will find a link to the Swing tutorial on "How to Use Menus". The tutorial contains a working example of using a popup menu. Compare your code with the tutorial to see whats different. We can't help you because we don't know what your code is like.
If you need more help post your SSCCE.
in the good old days what I did to solve this problem was to register a mouse listener with ALL the components.
you can write a fairly simple function that recursively traverses a top level container and do it.
this was with Java 1.1, so maybe there is a better option today.
One way off the top of my head would be to grab the coordinates of the clicks, and then have another method to determine if the clicks are on the tab, or inside of the content area of the tabs.

Categories