Rob Camick

+ Follow
since Jun 13, 2009
Merit badge: grant badges
For More
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

1) Don't use a null layout and setBounds(...). Swing was designed to be used with layout managers and a scroll pane will only work correctly when you use a layout manager
2) Maybe use use a GridLayout or BoxLayout since you appear to want the images to be displayed vertically. Read the Swing tutorial on Layout Managers for more information and working examples.
4 months ago

where the user can draw on BufferedImages,

That is not the best approach when you need to have the ability to undo painting.

I would instead suggest you do custom painting from an ArrayList of Points each time the component is painted.

Then for undo logic you simply remove the last Point from the ArrayList.

Check out the "DrawOnComponent" example from Custom Painting Approaches
4 months ago

just solved my problem but can you tell me what is the use of this setPreferredSize and setMinimumSize is java?

Well, you really should NOT be using setPreferredSize and setMinimumSize manually.

It is the responsibility of each Swing component to determine its own preferred/minimum/maximum sizes. Each layout manager can then use this information to determine the layout of the components. A layout manager can also choose to ignore this information.

Read the Swing tutorial on Layout Managers to better understand how these values are used by each layout manager.

The original problem with this question is that the code was using a null layout and therefore the preferred size of the panel was not being calculated correctly.

A scroll pane only works when the preferred size of the component is greater than the size of the scroll pane.

So, don't use a null layout and instead use layout managers, which is how Swing was designed to be used.

If you need to alter the preferred size for some reason then override the `getPreferredSize()` method of the component.
4 months ago
I really have no idea why you say you added it to the model? The prompt is NOT part of the model. The example above does NOT add the prompt to the model.

This class is a custom renderer.

Whenever you change the model of the combo box you need to reset the selected index to -1 to clear the selection so the prompt can be displayed.

I demonstrate this in the code above?
5 months ago
5 months ago
You really shouldn't be adding "Select Task" as an item in the combo box.

Instead, check out Combo Box Prompt for a custom renderer that will display a prompt when an item isn't selected.
6 months ago

Don't use a dummy catch block. How will you ever know if you have an Exception???

Don't use that constructor to create the Icon. Instead use:

ImageIO will generated an Exception if the image can't be found.

Actually you should be using the getResource() method to read the image. See: Loading images Using getResource()

Note that the image needs to be found on your classpath, so make sure you IDE is configured correctly.

Create the label with some default text just to make sure the label is displayed initially.

What is the point of those statements in your methods?

and tried every possible tutorial

Apparently you didn't try the Swing tutorial. I suggest you look at the trail table of contents and save the link for most Swing basics.

I would especially start with the section on layout managers and learn how to create your own GUI's and not rely on the IDE. You should NOT be using the AbsoluteLayout.,
6 months ago

Could you provide us with an SSCCE

The OP has been asked several times in the past to provide a SSCCE with every question.

I have a JTree with a TreeModel implementation.

Well, if you are using a custom implementation then maybe the implementation is the problem.

First verify your claim using the default classes when you create your SSCCE.

The problem is when I add a new child, the new child does not show in the tree view.

Works for me.

Does anyone know of a work around

There are different ways to add a node to the tree. You could be adding the via method of the model, or you could be adding the node to an existing node.

Depending on your approach the logic is slightly different.

We don't know what your code is currently doing, so we can't suggest what might be different. Hence the value of the SSCCE.
6 months ago

if the image is too big it will not fit on the screen

That is why you use a JScrollPane.

but I couldn't get the scroll on the panel where the BufferedImage is, probably because the scroll ignore the Buffered image size.

Did you override the getPreferredSize() method of the JPanel to be the size of the image?

Scrolling only works when the preferred size of the component is greater than the size of the scroll pane.

Read the Swing tutorial on Custom Painting for basic examples to get you started.
7 months ago

Swing provides many Abstract classes that implement most of the methods. In many cases they also provide "default" implementations of an interface. I guess the trick is to know when to extend the Abstract class or the "default" class.

I would suggest you not attempt to implement all the methods of an interface yourself. By minimizing the code you write you minimize the change in default behaviour and you minimize the risk of introducing an error.

If you google JFormattedTextField and TableCellEditor you only get two good results.

Gee, and I provided you with two working examples in this question and neither extend AbstractCellEditor.

You never actually replied if you tested the IntegerEditor. Since this editor uses a JFormattedTextField and adds bindings to the ActionMap/InputMap I thought it would have been a good place to start.

By extending AbstractCellEditor you are changing the default behaviour of your editor from default editors. The default editor for text, numbers etc. is only focused when you double click on the cell. Since the AbstractCellEditor doesn't have this "click count" concept to start editing I would guess it starts editing as soon as you click on the cell. Just a thought.

7 months ago
3 weeks ago you got multiple answers/suggestions to your original question.

Yet you didn't respond to either reply and now you expect more help even though you still haven't posted a reasonable SSCCE?

I thought you wanted an SSCE that you could copy and paste into an editor and it ran to illustrate the problem.  Which is what I did.  

And I gave you pointers on how you can improve upon the SSCCE in future questions.

Some of this code is in production so I really didnt want to change it and it didnt make sense to make a copy

And you still don't understand the basic concept of a SSCCE (so you haven't learned from my pointers).

We don't care about your application. We care about the stated problem.

Your question is about using a custom Date editor:

1. So you need a custom DateEditor class
2. You need a simple GUI to test the custom DateEditor class
3. You don't need a custom TableModel to test the DateEditor.
4. You don't need a custom renderer to test an editor.
5. You don't need custom application classes. Your code includes package statements and import statement for your application classes. I am not going go copy all those classes and create a directory structure that matches your package names. The one positive comment I gave to your original SSCCE was that is was contained in a single class file. Now you have 6 class files? How is that a SSCCE?

Below is some old code I have demonstrating a simple custom editor in the form of a SSCCE:

The idea of the SSCCE is to create your reusable editor code and create a simple test GUI. If you write the editor correctly, once you finish testing it then you just plug it into your application because it should not be dependent on any specific application logic.

If you can't get the editor to work then you have simple code to post on a help site that requires no application specific code.

Did you use "Increment Date" in both cases to only use one name in the action list or was that a mistake?

Yes it was a mistake, the name will be used when you add the Action to a JMenuItem or a JButton so it should be different, but it doesn't affect processing.

See: How to Use Actions for more information and examples.

Also check out Using an Editor to Validate User Entered Text. It is a complete working example that uses a JFormattedTextField to validate Integer data in a specified range. This should be a good starting point to create your custom DateEditor. It shows which methods you need to override. It is better to extend from the base class rather than implement all methods. The code already uses an ActionMap for some of the processing so you should be able to implement my earlier suggestions based on that code.

I am definitely NOT an expert on creating editors for a JTable. I have never done this before especially with a JFormattedTextField. Even if you post a SSCCE that more closely resembles the structure of the code above there is no guarantee that I can help.

However, I will not even attempt to look at the code you just posted. It is not even close to a SSCCE for me to look at. My time is valuable. This is the last time I will rant about a SSCCE. How you choose to post a question is up to you. Which questions I choose to answer is up to me.

7 months ago

I will be using a timer to reload the entire table periodically

If the pick up time has past, I want to change the color on that row to a different color, lets say red

You don't need to reload the data. You just use the Timer to repaint the table. The renderer should be able to compare the pickup time with the current time to determine the appropriate highlighting.

That is not how you add the renderer to the table.

1) The renderer is chosen by the class of the column. You don't override the getColumnClass(...) method of the DefaultTableModel. So the default class will be Object.class. None of the columns in your table contain data that is the OrderStatusRenderer.class. Your data is likely String.class or Integer.class or Date.class etc.
2) You can override the renderer for a specify column in the table buy specifying the renderer for the TableColumn. For example:

I'm not sure what your renderer is attempting to do:

Why would you have a Color in the TableModel? I would expect you have a Date of some kind so you can compare the date with the current data to provide the appropriate highlighting.

You did not post an SSCCE. We don't have access to your data so we can't possibly test the code provided.

I have scoured the web...,

I would suggest you read the Swing tutorial on How to Use Tables for some basics. The tutorial covers the basics of using a renderer.
8 months ago
1) you need a custom renderer to paint the background as required
2) you need a Swing Timer to repaint the table at a given interval so the renderer logic can be invoked.
8 months ago
Oops, my mistake, I understand the issue now.

As a workaround, add a FocusListner to the text field and manually add the special character when focus is lost.
8 months ago

for instance for the rate enter .2 and hit enter.

Seems to work in the Swing tutorial on How to Use Formatted Text Fields.

Formatting is done when focus leaves the field.
8 months ago