This week's giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Production-Ready Serverless (Operational Best Practices) and have Yan Cui on-line!
See this thread for details.
Win a copy of Production-Ready Serverless (Operational Best Practices) this week in the Cloud/Virtualization forum!

Rob Camick

Master Rancher
+ 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

Ok, so you have the data in the Workbook class. Now you need to use that data to create a DefaultTableModel.

So, in your looping code you need to create a Vector with the data in a Cell to represent a row in the table model.

Once you get a row of data in the Vector you add the Vector to the main Vector, so you have Vector of Vectors to represent the Excel data.

Then you use the Vector of Vectors to create the DefaultTableModel which is used to create the JTable.

Take a look at the code from lines 20-39 found in this posting:

It is similar to what you want. The difference is that it gets the data from a ResultSet. But it shows the concept of creating the Vector of Vectors.
2 days ago

I am now posting the function where the error occurs and the corresponding paint method.

You missed the point of my last comment.

You have NOT posted a SSCCE. How can we compile/text that code.

Again, we are not interested in your application.

You made a statement that drawstring(...) does not paint the contents of a variable properly.

So prove it. Post your SSCCE with a single drawstring and a single variable that contains the value you want to paint.

Get that simple code working first.

Once you get that working you will then realize the problem is NOT with the drawstring() method, but with your application code.

If is then up to you to debug your code to determine why your dynamic variables don't contain the value you think they contain.

3 days ago

The program is few thousand lines long.

That is completely irrelevant to your question.

Your stated problem is that you can't print the value of a variable correctly.

So, create a proper SSCCE to demonstrate your problem.

All you need to do is override the paintComponent(...) method of a JPanel and add the above drawstring(...) statement to do the painting.

You just need a variable to contain the data you want to print and then you hardcode the x/y location of the string.

Get this simple program working first so you understand the basics of how the drawstring() method methods to prove to yourself that is does work.

Then do debugging of your code to see what you are doing differently.

We can't offer any help with 3 random lines of code.
4 days ago

Why should same cellEditor instance be used for JCheckBox.

You can only edit a single cell at a time so you only ever need a single editor.  The default Boolean editor is designed to be generic so it can be used by all relevant cells.

I feel there is a bug in java swings's JCheckBox.

There is no bug, only your lack of understand of how renderers and editors are used to make efficient use of Swing resources by making the renderer/editor reusable.

Using TableModel or Key Released Event of JTable are different ways of accessing and modifying the individual cells in JTable.

No idea what you are trying to say. The TableModel contains data. You use the getVAlueAt(...) method to access the data.

5 days ago
Not really sure what you are trying to do, but I would suggest:

1. you don't need a custom editor

2. if you want to know the state of any cell in the table then you use the getValueAt(...) method to get the data in the cell. The data in the cell should be a Boolean value, so you just check if the value is TRUE/FALSE.

3. if you want to perform some action when a cell is clicked then you can add a TableModelListener to the TableModel. An even will be generated then you check the state of the Boolean value and do your processing.
1 week ago
How does your code look like the code from the tutorial?

Please download the working demo code from the tutorial.

Then customize the working code one step at a time. If the code stops working then you know what you just changed and you can fix it.

Learn from the working example.
2 weeks ago

it doesn't seem to recognize that the radio button is being clicked thus not registering the price

Correct. GUI's are event driven, which means the code needs to execute when the event happens, not when you create the GUI.

In the case of buttons you would use an ActionListener.

Now all the toppings are priced at 1.50 and are radio buttons

You should not be using radio buttons. Radio buttons are used to make a single selection from a group of buttons.

Instead you should be using check boxes, which allow you to select multiple toppings for the pizza.

Read the section from the Swing tutorial on How to Use Check Boxes for examples on how to use check boxes with ActionListeners.
2 weeks ago

you should have that running in some other thread, not on the GUI's event thread.

Already answered: with the same advice.

Boy is it frustrating when people repost.

Our time can be better spent helping people who don't already have answers to their questions.

When you cross post of 4 different web sites, then it is the job of the poster to update all 4 web sites with any information provided, so we don't spend time repeating advice already given.
2 weeks ago
15 replies into the question and I still have no idea what your real requirement is.

First you ask a question about "static". Now your question is about buttons.

I have multiple buttons that need to use a different instance of the dialog.

I'm not sure why you think you need a different instance. A JColorChooser is a temporary dialog. You display the dialog get the selected color and the dialog closes. You can use the JColorChooser.showDialog(...) method again. Yes internally the color choose may create a new instance of the JColorChooser class but that is of no concern to you. All you want is to get a selected color.

When I choose a color, it changes all the buttons not just the one being used

That statement makes no sense. If you invoke setForeground(...) or setBackground(...) on a single component, then only the color of that component should change.

In any case, where is your SSCCE demonstrating this problem?

Start with a JFrame with multiple buttons.

Then create an ActionListener that does the following:

1. Use the JColorChooser.ShowDialog(...) method to display the color chooser
2. get the button that was clicked by using the getSource() method of the ActionEvent
3. set the foreground of the button to the color selected

This is a generic listener that can be added to all three buttons.

Get this basic concept working and then fix your real program.
3 weeks ago

The above code creates a JColorChooser component that can be added to a JDialog.

The above code creates a JDialog with a JColorChooser component added to the dialog.

In this case the static method is really a convenience method. It will:

1. create a JDialog
2. create a JColorChooser component and add it to the dialog
3. add listeners to the components on the color chooser
4. show the modal dialog
5. close the dialog when a color is selected and return the color value for you

The reason the method is static, is because you don't need an instance of the JColorChooser to invoke the method. The method itself will create the instance.

If you don't like the default location of the dialog then you can't take advantage of the JColorChooser.showDialog(...) method.

Instead you need to manually code the above 5 basic steps. Once you create the child dialog (note child windows should be dialogs, not frames), then you can set the location yourself.

As has already been suggested you need to read the Swing tutorial on How to Use Color Choosers.

The code you posted basically does nothing. The ColorChooserDemo code from the tutorial shows you the minimal amount of code needed to display the color chooser manually. Download the code and play with it.

Now you need to decide if it is worth it just to display the chooser at location (0, 0).
3 weeks ago

I can change the color of the Jframe background from the Jpanel,

You are not changing the color of the frame. You are changing the color of the panel. The panel covers the entire frame.

You added the MenuPanel to the content pane of the frame. The panel fills the entire content pane so you see the color of the panel, not the frame.

A couple of problems with this statement:

1. Class names should start with an upper case character.
2. You should NOT be extending JFrame. There is no need to extend any class. You are writing an ActionListener. All you need to do is implement the methods of the ActionListener.

Again, you can't change the content pane because the panel cover the entire content pane. You can change the color of the panel with code like

I suggest you read the Swing tutorial on Using Top Level Containers for some Swing basics. Keep a link to the tutorial handy. It will also show you other Swing concepts, like how to use listeners.
3 weeks ago

slightly better than all the indexOf

Just wanted to point out there is no need for any indexoOf() statements based on my suggestion.

The first substring() (always) starts at index 14 and goes to the length of the string - 1.

The substring() on each color (always) starts at index 2.
3 weeks ago

A series of statements using indexOf and subString.

I might do something like:

1.substring() to get the: "r=255,g=0,b=0"
2. String.split on "," to get an array containing the 3 colors.
3. another substring() on each of the 3 values to get the String number
4. convert each String number to an int.
5. create the Color from the 3 int values.

Brute force, but the only way I know how to do it.
3 weeks ago