Extending JXDatePicker for Time JComboBoxes - java

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.

Related

How to make JTextFields clickable?

I posted a similar question a year ago, but it was not really well written and I didn't get an answer I could work with. Now I stand in front of the same problem. I got a JPanel (my content pane), where a MouseListener is implemented.
Everywhere I click, I get the exact coordinates of my mouse click. Except my JTextField components. When I click on those, the MouseEvent isn't even triggered. H
ow do I do this, so my mouse clicks on those will also call the mouse event?
Tried: setEnable(false) and setHighlighter(null)
Sorry thought I fixed the X/Y problem.
The X/Y problem simply means you are telling us what your attempted solution is without telling us what your requirement is. We can't suggest a different approach if we don't know what you are trying to do.
I want to open a menu,
Now we know what the requirement is.
The solution is to add the MouseListener to the text field, not the panel. If you have the same popup of the panel and the text field, then you still need to add the listener to both the panel and the text field.
You can do this in one of two ways:
Read the section from the Swing tutorial on Bringing up a Popup Menu for a working example.
Note the above tutorial is a little old, you can also check out the setComonentPopuMenu(...) method of the JComponent class. This approach will create the listener for you.

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.

How to have Button click show combo options

I apologise if this is a bit vague, I know exactly what I want but I am finding it hard to describe/google.
What I have is a swing GUI with a JTable with some connection information and status' in for several connections. In the bottom row I have a "plus" icon JButton and which can add a connection.
There are two different connection types, so what I want is to click on the button, and then the two options appear next to the button in order to select one before moving on.
It would be a similar look to if you had right-clicked on the button, the options would be "above" the table in a list/combo box style, slightly to one side of the button.
Can anyone help me with this?
Thank you very much in advance.
Rob
We've managed to solve the issue using JPopupMenu, which nicely provides what we wanted.
See http://docs.oracle.com/javase/tutorial/uiswing/components/menu.html#popup

Animated table of strings

I'm trying to write a scorekeeping app in Java that allows a server application to send scores to client applications. The clients will then display a list of teams, team IDs and their scores, sorted by score. Of course I could just use a swing JTable to display everything, but I want to achieve a unique effect: I want the text dynamically reorder itself every time a team moves up in the list. That is, it want to animate the text around the screen. I would also need to be able to update the contents of the labels after being added. What would be the best way to achieve this? Is there any component that allows you to add other components to it and place/move them freely?
JTable is a JComponent so you can set desired LayoutManager and add JLabels above the JTable. Then move/reorder them to achieve desired effect. See SwingWorker as well.
You could use a JTable and change the contents of the rows as teams move up. Or you could arrange a series of labels and change the text whenever you want. To change the value displayed for a JLabel you simply use the JLabel.setText("new value"); method.
I've never done this but I think you need to use a panel with a 'null' layout manager. Meaning you are responsible for absolutely positioning your elements
http://docs.oracle.com/javase/tutorial/uiswing/layout/none.html
You would need some kind of SwingWorker or Timer running to update the gui layout. Make sure you actually make the GUI changes on the EventThread, which you can do by using SwingUtilities.invokeLater();
As alternatives to a null layout, consider letting the layout work for you using
one of the marquee effects discussed here, or
shuffling labels in a suitable layout, shown here and here.

Problem in obtaining the focus of JTable?

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.

Categories