Rob Camick

+ Follow
since Jun 13, 2009
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Rob Camick

Quit cross posting:

You were given the same answer yesterday.

Its frustrating when we take the time to help and you completely ignore the advice given.

4 days ago

locationToIndex is what I am using. I want it to return -1 if I click an empty space, instead

Then override the method to do what you want.
6 days ago

replicate something I see in popular UIs

Not sure where you see that.

1. How do people know that clicking there will create a new value?
2. What happens when the JList is full and there is no space to click?

Normal UI design is for a click to "select" an item and then a double click will invoke a default Action on the selected item.

Other normal conventions are to right click to display a popup menu to display a list of Actions that can be performed.

Also, a UI should be designed so that is can be used with a mouse or the keyboard.

Advanced users use the keyboard because it is more efficient. Beginners use the mouse.

So how would users use the keyboard to move beyond the last item to invoke the create logic?

1 week ago
Where is your SSCCE?
1 week ago

The main thing holding me back from doing it all through code is the jlist starts off at 0px if its empty.

Not sure why you say that.

The JList has a default size when I run:

I can then control the size by adding:

The above code example is called a SSCCE.

Every question should contain a SSCCE so we can verify the code you are using.
1 week ago
I don't recommend using an IDE to generate your code. You spend time learning the IDE and not learning Swing.

The key to layout design is to logically group components onto a panel and then use an appropriate layout manager to display the components.

The trick is that you can nest panels with different layout managers as necessary.

Maybe start with the working code found in the Swing tutorial on How to Use Lists,

The tutorial also has a section on "Layout Manager" which contains working examples of each layout manager on its own.

I'm not sure why you show the bottom row with 3 columns, since there are no components being displayed.

So assuming you really only need a layout with 3 columns I might suggest you start with:

1. use the default BorderLayout of the frame
2. Add your JScrollPane containing the JList to the BorderLayout.LINE_START
3. Create a JPanel with a GridLayout and add it to the BorderLayout.CENTER
4. Create a panel for the "Add From File" components and add components to the panel and add the panel to the grid layout panel
5. Create another panel for the "Class Name" components and add the panel to the grid layout panel

so the key to to start with a top level logical design for each panel and then repeat the process as you get into more detail for each panel.

You will eventually learn which layout manager to use in a particular situation.
1 week ago
Only valid data should be displayed in the combo box.

1 week ago
There is no way to force the user to select a value.

You can only check if the item returned from getSelectedItem() is null after following Paul's suggestion and provide and do error processing.

You maybe also want to use the approach as demonstrated by the Combo Box Prompt.

The class from the link with allow you to display a prompt in the combo box when no item has been selected.
1 week ago
Read the section from the Swing tutorial on Concurrency.

It will explain more abut the Event Dispatch Thread (EDT) and give an example of how you can use a SwingWorker to create a separate thread.
2 weeks ago

On the button object and the object with the background  to change after all the changes have been called.  use

Not necessary. In addition to Norm's comment:

When a property of a Swing component is changed the component will automatically invoke revalidate() and repaint() on itself.

2 weeks ago
I would guess your filter is written incorrectly.

Post a proper SSCCE demonstrating the problem.
3 weeks ago
Here is a basic example that shows how this can be done with hard coded data:

In your case because you get the cities from a database you would need to modify the ActionListener to get the data from the database and build the ComboBoxModel.
3 weeks ago
1) that is not your name. Follow the rules of the forum
2) You didn't use the code tags when you posted your code
3) You have cross posted this question in another forum:
4) You were asked for more information in your other question. The same applies here.

In this forum it is called a SSCCE.

A proper SSCCE needs to be included with your question since your question is not clear. Reposting the same question in another forum does not make it clearer.

5) Don't add your question to another question. There should only be a single question per thread.

Improve your question using the above suggestions and repost the improved question, NOT the same question.
1 month ago
Here is an example of a SSCCE:


1. There is no need for a custom TableModel. The DefaultTableModel will work just fine.
2. How to create hard coded data to test a concept.

If you do want to create a custom TableModel then I suggest you follow the steps provided in this example:

Row Table Model

If you want generic code to load data from a database then check out:

Table From Database

The "TableFromDatabase" should be able to load any data given a proper SQL statement.
1 month ago

when the mouse is not over a rectangle region the tooltip shouldn't appear or at it least it should be empty

That is what I suggested.

You modify the code to return null when the mouse is not over a Rectangle.

The code I gave was a quick demonstration of how to override the method.

You need to customize the logic for your requirement.

So I would suggest your panel needs an ArrayList of Rectangle objects. Then you iterate through the ArrayList to see if you any Rectangle contains(...) the mouse point and set the tool tip appropriately.
1 month ago