Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ah, yes, selection is different. You can use the methods on JTable to select both the row and column setRowSelectionInterval(int index0, int index1) and
setColumnSelectionInterval(int index0, int index1).

You'll still need the highlight renderer if you want to make a cell red.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I just posted an example of this over in a similar thread about JTable here. Perhaps it will help.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

There is not a row renderer per se, so you have to install a cell renderer on all columns that will check the particular column values and apply the formatting as necessary.

Here is a skeletal highlight renderer to give you an idea to work from

class HighlightRenderer extends DefaultTableCellRenderer {

    private final Color HIGHLIGHT_COLOR = Color.YELLOW;

    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {

        Component comp = super.getTableCellRendererComponent(table, value, isSelected,
                hasFocus, row, column);

        if ( [highlight condition] ) {
            if (isSelected) {
                comp.setBackground(new Color((HIGHLIGHT_COLOR.getRGB() 
                        ^ comp.getBackground().getRGB())));
                comp.setForeground(new Color(Color.BLACK.getRGB() 
                        ^ comp.getForeground().getRGB()));
            } else {
                comp.setBackground(HIGHLIGHT_COLOR);
                comp.setForeground(Color.BLACK);
            }
        } else {
            if (isSelected) {
            } else {
                comp.setBackground(Color.WHITE);
                comp.setForeground(Color.BLACK);
            }
        }
        return comp;
    }
}

You can install the renderer directly on the columns

TableColumnModel colModel = table.getColumnModel();
            for (Enumeration<TableColumn> colEnum = colModel.getColumns(); colEnum.hasMoreElements();) {
                TableColumn c = colEnum.nextElement();
                c.setCellRenderer(new HighlightRenderer());
            }

or override getCellRenderer() on the JTable as noted in the JTable tutorial here.

mKorbel commented: that job for prepareRenderer, don't do it that this way +8
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Not technically correct. In Java, everything is passed by value. You can read about it here.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Anthrax - Got The Time

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I agree with web-guy's earlier suggestion that you probably need to outer join your customer table to your invoice table for the sums. I assume that the customers who have no orders have no records in the invoice table. If they aren't in the table, they aren't going to appear in your group by results.

Try using [customer table] left outer join [invoice table] on the customer Ids.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Try starting with this: http://download.oracle.com/javase/tutorial/2d/geometry/index.html

Edit: Actually, that one is thin on simple example code. Try this one first: http://download.oracle.com/javase/tutorial/uiswing/painting/index.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, yes that does reverse a string, but that still wasn't the exact question asked by the OP in 2009. They needed to also retain the word order.

There is also no reason to initialize str1 as new String() . Use a string literal instead String str1 = "My String"; This thread is marked solved by the way, so there really isn't much reason to resurrect it to post non-solutions.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Either of these work (I named the temp table qtest for no good reason)

SELECT *, q2.holding-q1.holding AS change 
FROM (SELECT * FROM qtest WHERE date=DATE'2010-12-31') q1,
(SELECT * FROM qtest WHERE date=DATE'2011-03-31') q2 
WHERE q1.account=q2.account and q1.product=q2.product
SELECT *, q2.holding-q1.holding AS change 
FROM qtest q1 INNER JOIN qtest q2 ON q1.account=q2.account AND q1.product=q2.product 
AND q1.date=DATE'2010-12-31' AND q2.date=DATE'2011-03-31'

I left the "*" selection there just so you could verify the join result. You certainly don't need all those displayed.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

My preference is H2, but JavaDB/Derby is a fine embedded database as well.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can try replaceAll("<.+?\\>", "")

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Javac.exe is used to compile a .java source file. Java.exe is used to run a compiled class file or jar file.

You can learn how to use those tools here.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The problem is that the GridLayout sizes each grid cell the same, so when you increased the height of your textfield by changing the font size, you increased the height of all rows in the grid.

To get around that you could use a BorderLayout of two panels, one with your text field at the top and another for all of your other buttons in the center.

That would allow you to separate the sizing of the two sections. Take a glance at this change to your layout code

//Setting the layout
JPanel upper = new JPanel();
upper.setLayout(new GridLayout(1,1));
upper.add(jtfTxt);

JPanel lower = new JPanel();
lower.setLayout(new GridLayout (13, 1, 2, 2) );
lower.add(p1);
lower.add(p2);
lower.add(p3);
lower.add(p4);
lower.add(p12);
lower.add(p5);
lower.add(p11);
lower.add(p6);
lower.add(p7);
lower.add(p8);
lower.add(p9);
lower.add(p10);

f.setLayout(new BorderLayout());
f.add(upper, BorderLayout.NORTH);
f.add(lower,BorderLayout.CENTER);
f.setJMenuBar(mb);
f.setResizable(false);
f.setBackground(Color.black);
f.pack();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
mKorbel commented: good suggestion +1 +8
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Not only is it late, it's not the solution.

It's perfectly valid to specify the insert fields as well as the values

INSERT INTO <tablename>(field1,field2..) VALUES (value1, value2..)
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This old thread from 2005 was revived by someone advertising their software library. That spam post has been deleted and I'm going to close this thread we don't get more people treating this as an open question.

@sirlink99: I'd encourage you to try Norm's suggestion above. It may turn out differently than you expect.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Anchoring solved the problem. Thanks

Try playing around with 'fill' next.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

wrong :-)

Not wrong.

It addresses on of the problems he describes. I'm looking at the result right here on my screen ;)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Consider anchoring.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You'll be able to see the locations easier if you change all of those 9, 17, etc to simpler values like 0,1,2 to address the cells. There is no reason they need to be so large. Also remember that indexing begins at 0.

So your "+/-" button should be located at gridx=2, gridy=4 if you normalized those grid positions.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Consider that components don't fill their grid cells unless you specify that in the constraints. The default is no fill.

You also need to specify how "extra" space gets divided up horizontally and vertically with the weightx and weighty properties. The default is 0, so if you want a component to take some of that extra space you need to set a value for it 0 < weight <= 1.0 GridBag is just one of those layouts you have to work with on your own until you "get it" and that can take a little time.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you want the components to fill space horizontally or vertically, you need to set that with the 'fill', 'weightx' and 'weighty' properties.

'anchor' will let you set which side components are "stuck to".

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I think you are confusing grid cells and pixel dimensions.

You only need to use setPreferredSize if you want to change the default size in pixels for a component. That is unrelated to how many grid cells that a component may occupy.

If your component are now on top of one another, then you have not placed them into the proper grid cells with 'gridx' and 'gridy'. You were pretty close with the layout posted above, but as I mentioned, you don't need to use multiples of 4 to specify the grid cells. 0,1,2, etc will suffice.

They are just cell locations in a grid of hypothetical squares - not actual heights/widths.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Sorry, the method is actually setPreferredSize(Dimension)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Why are you using widths/heights of 4 and 8, instead of simply 1 and 2?

> Also no matter what I change the button sizes to they stay the same size.
You can call setPreferredWidth() on your buttons to specify their preferred size to the layout manager.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Did you bother to read any of the tutorials that mKorbel linked for you?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Check it for what?

You didn't implement the equals() method as Masijade already suggested.

Read this if you need a detailed explanation.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You need to read about using Layout Managers.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

i've put the exception ..............

No, you haven't.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you can't even be bothered to post the exception, then why should anyone waste their time trying to figure out what's wrong with this for you?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

There are a wealth of them. Just look through the other tutorials listed to the left in that one I linked to you. Explore other parts of that site and the API docs as well.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can use JFileChooser for those things.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No, that's really about it. You have to check against all four bounds for containment.

If you're using Rectangle to store the rectangles, you can use its contains() method, but it does pretty much the same calcs you are doing there.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Have you tried taking out the repaint() call? I can't see why you would need that in your constructor.

You may also want to use requestFocusInWindow() instead of grabFocus().

Anuradha Mandal commented: Just stop it .If I do wrong , please then correct me, but dont insult. +0
peter_budo commented: Equalizer +16
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Take a look through the tutorial on using tables and stop hijacking the OP's thread with your own questions.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

>Data can not be edited in a Jtable.
It certainly can be edited and saved back to the database. Ignore this nonsense.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Merged duplicate threads. Please do not post the same question multiple times.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Perhaps you can start here and when you have specific questions, post them in the C forum.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Probably added after the post.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I already solved it......

Yes, I am aware of that.

Pardon me for mentioning additional information that I though you might find useful. String matching error messages isn't really the most robust way to isolate the nature of error conditions.

mKorbel commented: i can't see reason for donw-voting +1 +8
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

> I think I get why you have to put -x, because the Graphics2D scaled the "x" with -1 so it would be inverted, right?
Yes, with the entire transform inverted like that, the x value you pass to the method actually ends up being an offset to the left instead of to the right.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

To get it to actually render in the correct location, I also had to negate the x position in the super.paintIcon() call to account for the inverted scaling:

super.paintIcon(c, g2, -x, y);

@yancuoto: I would also recommend extending JComponent instead of Component and overriding paintComponent() unless you have to mix this with other heavyweight AWT components.

yancouto commented: Thank you man, you really helped me! +2
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, but one is partially occluded by the other because I did not alter any of the positioning code to account for differences in image width.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The code works just fine here. Check the size and positions you're painting the icons, because I think you're just overlapping them.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Take a look at the SQLException api. There are methods to get SQL State and the Error Code, which will often provide the specific info you're wanting.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Changing from Choice (AWT component) to JComboBox (Swing component) cuts the time in half roughly.

Using JTextfield makes it nearly instant and I can't see any benefit at all to using the combo boxes to choose a number 1-100.

Seems like a JTable would be a preferable UI choice.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It's currently optimized for the key phases "Thanks for sharing" and "Do SEO to get backlinks to ur site."

jingda commented: Lol:) +0
Salem commented: LOL +0
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Duplicate threads merged. Please excuse the minor discontinuity.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

> By the way, rather than bring an old thread live - it might be better to start your own thread.
Not really, if the only intent of that thread is to spam signature links related to the topic...

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

>Sorry, thought responders would have enough experience to know code from explanation
It's not about level of experience of the responders, it's about courtesy to those who might volunteer their own time to try help you out. Code tags make the code much easier to follow.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Welcome aboard!