Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!

Duane Riech

Ranch Hand
+ Follow
since Feb 27, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Duane Riech

Thanks for the reply...
Yes, I finally figured it out yesterday.

Thanks again
16 years ago
I have a JTable which is NOT editable, but I do want the background color
to change to indicate that the row has been selected. Notice that I call
setSelectionBackground() but this doesn't do anything.
Thanks...
ItemTable = new JTable( tableDataModel );
ItemTable.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
ItemTable.setDefaultRenderer( String.class,
new ItemTableCellRender(ItemDisplayData));
ItemTable.setRowSelectionAllowed(true);
ItemTable.setSelectionBackground( Color.BLUE );
ListSelectionModel ItemModel = ItemTable.getSelectionModel();
ItemModel.addListSelectionListener( new ItemSelectionModel() );

ItemTable.setPreferredScrollableViewportSize(new Dimension(500, 650 ));
16 years ago
I have a MS Access table which contains a Date tag on each record.
I want to retrieve records based on:
Today - 1 month
or
Today - 2 weeks
etc.
Can anyone tell me the syntax?
Thanks
You're right....
Stupid mistake...
My apology....
16 years ago
I'm studying up on the Printable interface and am trying to use an example from a book. I'm getting compile errors on the variable g2, (Marked in code).
Since class Graphics2D is abstract and I'm subclassing from parent Graphics g, I don't understand what the compiler wants.
This is just part of the code containing the class.

Thanks...

PrinterClass.java:187: cannot resolve symbol
symbol : variable g2
location: class Project.PrinterClass.paintContent
int y = g2.getFont().getSize() * 5 / 2;
^
PrinterClass.java:189: cannot resolve symbol
symbol : variable g2
location: class Project.PrinterClass.paintContent
g2.translate( xo + x, yo + y );
^
PrinterClass.java:191: cannot resolve symbol
symbol : variable g2
location: class Project.PrinterClass.paintContent
AffineTransform old = g2.getTransform();
^
PrinterClass.java:193: cannot resolve symbol
symbol : variable g2
location: class Project.PrinterClass.paintContent
g2.drawString( RecipeTitle, 0, 0 );
^
4 errors
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.Graphics2D;
import java.awt.print.*;
..
..
..
..
class paintContent implements Printable {
public int print( Graphics g, PageFormat pf, int pageIndex ) {

/*
* Construct a new Graphics2D object.
*
Graphics2D g2 = (Graphics2D) g;
/*
* Get the width, in 1/72nds of an inch, of the imageable area of the page.
*/
double width = pf.getImageableWidth();
/*
* Get the height, in 1/72nds of an inch, of the imageable area of the page.
*/
double height = pf.getImageableHeight();
/*
* Get the x coordinate of the upper left point of the imageable area of
* the class Paper object associated with this PageFormat.
*/
int xo = (int) pf.getImageableX();
/*
* Get the y coordinate of the upper left point of the imageable area of
* the class Paper object associated with this PageFormat.
*/
int yo = (int) pf.getImageableY();

String Title = " Title : Gone with the Wind";
int x = Title.length() / 10;
Error-> int y = g2.getFont().getSize() * 5 / 2;
Error-> g2.translate( xo + x, yo + y );
Error-> AffineTransform old = g2.getTransform();
Error-> g2.drawString( Title, 0, 0 );
return Printable.PAGE_EXISTS;
} /* ...end of method print()... */
} /* ...end of class declaration paintContent... */
16 years ago
The reason for the question was in reference to a drag and drop
implementation from a JTable to a JDialog. Since the JDialog would
be covered once the dragsource was clicked on, I wanted a way to
force the JDialog to stay on top as the dragTarget.
I implemented a "class ComponentEvent extends ComponentAdapter"
and included the componentHidden() method to trap hidding the JDialog
and included the addComponentListener(new ComponentEvent()); line in
the JDialog public constructor. I wanted to make a call to toFront(),
but I'm not trapping the Hidden event for some reason.

Either way, I'm sure there's another way of dealing with the issue.
Thanks for the responses.
16 years ago
Is there a way to force a JDialog (non-modal) to always be on top??
Thanks,
16 years ago
I'm using a boolean value as a column within a JTable. I want to change the color of a JCheckBox from black to red in the column based on a test.
I created a class to extend JCheckBox which implements TableCellRenderer. When the JTable is displayed, the checkbox is there, but you can't see the check in the box until you press the mouse key on the checkbox.
Here's the setup of the JTable:
TableName.setDefaultRenderer(Boolean.class,
new gridTableCellRenderer(DisplayData));

If I comment out the line above, the checkbox appears correctly showing the checked or unchecked condition without depressing the mousebutton.

Here's the class itself:
package NewPackage;

import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.util.*;

class gridTableCellRenderer extends JCheckBox implements TableCellRenderer {

private Vector DisplayData = null;
public gridTableCellRenderer( Vector DisplayData ) {
super();
// setOpaque(true);
this.DisplayData = DisplayData;
}
public Component getTableCellRendererComponent( JTable table,
Object value, boolean isSelected,
boolean hasFocus, int row, int column ) {
Display record = (Display) DisplayData.get(row);

if ( record.getItemID() == 0 ) {
switch( column ) {
case 0:
// setBackground(Color.red);
// setForeground(Color.black);
// setEnabled(false);
break;
case 3:
// setForeground(Color.red);
break;

default:
break;
} /* ...end of switch statement... */
} /* ...end of if ( record.getItemID() == 0... */
else {
switch( column ) {
case 0:
// setBackground(Color.lightGray);
// setForeground(Color.black);
// setEnabled(true);
break;

case 3:
// setForeground(Color.black);
break;

default:
break;
} /* ...end of switch statement... */
} /* ...end of else statement... */
return this;
} /* ...end of method getTableCellRendererComponent()... */
} /* ...end of class declaration gridTableCellRenderer... */

As you can see, I've commented out all of the logic in an effort to try to find out what was causing the problem. As I said before, the only way I can get the checkboxes to appear correctly is commenting out the line:
TableName.setDefaultRenderer(Boolean.class,
new gridTableCellRenderer(DisplayData));

Thanks in advance....
17 years ago
Yes, that works.
Thanks alot.
17 years ago
I know this is very basic question but I can't get a clear example.
I have created a class that extends JDialog.
I want to create an instance of it from within a JPanel which has as it's
ultimate parent a JFrame.
How do I get the "owner" or first parameter for the super() call? I tried
getContentPane() but then I get a compiler error.
I'm not finding enough documentation in my reference books to understand
what it needs.

Thanks,

public class IngrIdentDialog extends JDialog {
public IngrIdentDialog( Dialog parent, String title,
boolean modal, Vector data ) {
super( parent, title, modal );
} /* ...end of public constructor IngrIdentDialog... */
} /* ...end of class declaration IngrIdentDialog... */
-------------------------------------

IngrIdentDialog dialog = new IngrIdentDialog( getContentPane(),
"a title",
true );
17 years ago
I have a rather odd request.
I'm working on a groceries application which uses the item's UPC
code and description. I've been trying to build a UPC database by accessing
data through the Internet and direct communication with the various food manufactures.
I�ve contacted Walmart, Kraft and other entities requesting JUST the UPC code and description, NOT price information. I�ve been turned down every time. Apparently they�re afraid of misrepresentation but of what kind I�m not sure. I have downloaded the
http://sourceforge.net/projects/upcdatabase/ database, and while appreciated, it�s a limited subset.
I�ve had a couple of email conversations with Gregg London regarding his database but it�s WAY to expensive for me (unemployed software engineer).
Maybe I'm being naive, but UPC item data, less the pricing information,
shouldn't be that big of a deal, but everyone I talk to on the Internet
seems to be very coy about the information. I would think manufactures would
want people to know about their product.
Anyway, if anyone has worked with UPC data, could I please get a copy of your data? I would really appreciate it.
Thank you very much�
duane_riech@msn.com
17 years ago
Can anyone tell me why I'm getting a NullPointerException on this piece of code?

private void IngrstopAllCellEditing() {

for( int i = 0; i < IngredientDataModel.getRowCount(); i++ ) {
for( int j = 0; j < IngredientDataModel.getColumnCount(); j++ ) {
javax.swing.table.TableCellEditor editor =
IngredientTable.getCellEditor(i, j);
System.out.println(" row <" + i + "> column <" + j + ">" );
try {
if ( editor != null )
editor.stopCellEditing();
} /* ...end of try statement... */
catch( NullPointerException ex ) {
System.out.println(" Nullpointer - row <" + i + "> column <" + j + ">" );
}
} /* ...end of outer for loop... */
} /* ...end of outer for loop... */
} /* ...end of method IngrstopAllCellEditing()... */

My JTable displays the last column of data, as defined by my
TableModel, columncount = 4.

row <0> column <0>
row <0> column <1>
Nullpointer - row <0> column <1>
row <0> column <2>
Nullpointer - row <0> column <2>
row <0> column <3>
Nullpointer - row <0> column <3>
row <1> column <0>
row <1> column <1>
Nullpointer - row <1> column <1>
row <1> column <2>
Nullpointer - row <1> column <2>
row <1> column <3>
Nullpointer - row <1> column <3>
row <2> column <0>
row <2> column <1>
Nullpointer - row <2> column <1>
row <2> column <2>
Nullpointer - row <2> column <2>
row <2> column <3>
Nullpointer - row <2> column <3>
row <3> column <0>
row <3> column <1>
Nullpointer - row <3> column <1>
row <3> column <2>
Nullpointer - row <3> column <2>
row <3> column <3>
Nullpointer - row <3> column <3>
row <4> column <0>
row <4> column <1>
Nullpointer - row <4> column <1>
row <4> column <2>
Nullpointer - row <4> column <2>
row <4> column <3>
Nullpointer - row <4> column <3>
row <5> column <0>
row <5> column <1>
Nullpointer - row <5> column <1>
row <5> column <2>
Nullpointer - row <5> column <2>
row <5> column <3>
Nullpointer - row <5> column <3>
17 years ago
I'm using a JTable which includes a boolean value and a String.
I've written classes to extend JCheckBox implements TableCellRenderer and
IngrTableCellRender extends DefaultTableCellRenderer for the String.
Under certain conditions, I want to display a row in red, so I've implemented a setBackground(Color.red) and setForeground(Color.red) respectively, in each class. Everything works ok.
I'd ALSO like to disable the JCheckbox whenever I paint the row red. I included a line setEnabled(false); in the JCheckBox class, but I can still click the checkbox.
The getTableCellRendererComponent() routine IS being called and I'm executing the setEnabled() code.
In short, everything works, except I can't disable the JCheckBox.
Any ideas?
Thanks....
17 years ago
I'm having a problem displaying a icon and I appreciate any help
I could get.
I have a app with three panes; top, middle and bottom, each using GridBagLayout.
The top panel (JPanel) displays a JLabel on which I put a icon (.gif). The
original .gif has a width of 200 and height of 450.
I use getScaledInstance() on the image to reduce it to about 200 by 200.
On INITIAL display, everything looks fine, but on a RESIZE the layout manager
tries to display the entire height of 400, so I end up with the top panel
and nothing else.
I can't figure out if it's a problem with the image or my constraint settings
which are as follows:
setLayout( new GridBagLayout() );
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 2;
c.gridheight = 1;
c.fill = GridBagConstraints.BOTH;
c.weightx = 1;
c.weighty = 0.5;
add(TopPanel,c);

c.gridx = 0;
c.gridy = 2;
c.gridwidth = 2;
c.gridheight = 1;
c.fill = GridBagConstraints.BOTH;
c.weightx = 1;
c.weighty = 0;
add(new JPanel(false),c); // Just padding between top and middle
c.gridx = 0;
c.gridy = 4;
c.gridwidth = 2;
c.gridheight = 1;
c.fill = GridBagConstraints.BOTH;
c.weightx = 1;
c.weighty = 0.5;
add(MiddlePanel,c);
c.gridx = 0;
c.gridy = 6;
c.gridwidth = 2;
c.gridheight = 1;
c.fill = GridBagConstraints.BOTH;
c.weightx = 1;
c.weighty = 0;
add(ButtonFrame,c);

Thanks in advance....
17 years ago
I'm using a JLabel to display a .gif in a portion of a GUI.
Is there any way to shrink or expand a .gif file to fit the size of the
label? In some instances, only part of the .gif is visible due to the
original size. Since making the .gif the exact size prior to display is
probably not going to happen, can I resize it?
Thanks....
17 years ago