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

What does a JFileChooser have to do with setting the background color of a frame?

I'm not understanding your question.
17 hours ago
Not really sure what you are doing.

It looks to me like you are extending JButton and attempting to add a label to the button.

Instead you should be adding the label to the panel.

When adding components to a visible GUI then basic code is:

1 week ago
By default Swing components have a size of (0, 0) so there is nothing to paint.

A component is given a size/location by the layout manager.

The layout manager is invoked when the frame is "packed" or made visible (which is why it works in your first case).

If you add a component to a visible GUI then you need to use:

The revalidate() will invoke the layout manager.
2 weeks ago

Now I have no idea what I'm doing wrong

I have no idea what you are asking.

You just stated the code is now working. You have made problems to fix the original code and the code posted here is correct. Your original code was wrong.

Since I'm using the Observer pattern

The code posted here is NOT using the Observer pattern and there is no need for it to do so.
3 weeks ago
One issues is that the try/catch  block should NOT be part of the painting method.

A painting method should only do painting. Is should NOT do I/O as this will slow down painting.

Don't know if there are other issues. Post a proper SSCCE to demonstrate the problem.
3 weeks ago

Is it possible in Java to create an empty JTable

Use the DefaultTableModel to create an empty JTable.

Then you use the addRow(...) method to add rows of data as required.

After I entered all of the employee data it has to export to a .CSV file

Then you iterate through the TableModel using the getValueAt(....) method and write the data to a file in any format you desire.
4 months ago

Swing components have a parent / child relationship.

If you want components to overlap then you add the child component to the parent component.

Yes I want background then in the center, I put a panel.

The parent component should use a layout manager to position the child are required. In this case the easiest way is to use a GridBagLayout.

So the basic code might be something like:

See: Background Panel for a more flexible background component.
4 months ago

what am i missing from this code?

We don't know.

The trace tells you the exact statement causing the problem. We don't know what statement that is.

So find the statement, find the null variable and fix the problem.

This is standard debugging.
5 months ago
The ActionListener can be shared by both buttons.
5 months ago
And what is your issue?

Displaying two tables is no different that displaying two labels or two buttons or two text fields.

Read the Swing tutorial on How to Use Tables
5 months ago
For each batch I would create a JPanel with:

1. a JLabel for the batch number
2 a JList (in a JScrollPane) for the details.

Then you can add a MouseListener to the panel to enable dragging of the panel around the screen.

Check out the Basic Dragging example code found in Moving Windows
5 months ago
Code seems to work fine for me.

However a few comments:

1. Don't use setPreferredSize(...). It is the job of the layout manager to determine the size of the panel and it is the job of the component to determine its own preferred size

2. Don't use: new JTextField(). Instead use new JTextField(10). Change the number as required. This will allow the text field to size itself to display 10 "W" characters at one time.

6 months ago

I asked for an easy fix

You have 4 issues.

I gave you multiple easy fixes to fix most problems.

The layout manager is the last issue to fix and was really a comment for the future.

I am not sure how to refactor my code to fix that

You don't need to refactor your code to:

a) try a different image size
b) read the JLabel API to align the text to the right
6 months ago

but could you give me a quick reply on how to easily fix this issue?

I did.
6 months ago

Namely static abuse, but I don't know how to fix it

Get rid of all the static variables and method.

The only method that needs to be static is the main() method.

reddit icon not resizing

Looks reasonable to me. I would say the image is 120x120.

Try playing with the size to see the difference.

text getting cut off by said icon

Don't use a null layout. This is the biggest problem beginners have. I have no idea where you learn to use a null layout.

Swing was designed to be used with layout mangers. Every tutorial I have seen uses layout manangers.

Read the Swing Tutorial.

There are working example for all Swing components. Every tutorial demo code will use layout managers.

There is also a separate section on Layout Managers with basic example of using each layout manager.

You can use the GridBagLayout for displaying components is row/columns.

text not centered

Read the JLabel API. There are methods to control the positioning of the text.

Also, typically numbers like that would be right aligned.
6 months ago