🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.swing
5 messages
5 total messages Started by Hiroshi Sun, 28 Aug 2005 02:36
overridden JTextField in JDialog
#345
Author: Hiroshi
Date: Sun, 28 Aug 2005 02:36
16 lines
1677 bytes
Hi everyone, a JTextField in a JDialog (or its extended class)ends up with mostly-overridden by paint() for the dialog. Below is the code to demonstrate the problem. When paint() is not included in the dialog class, the field is normally shown, but with it, the field is almost lost. Will you tell me why and how I can avoid this problem? (I do need to include paint() in the dialog class.) Thank you.

PS paint() is called right after add() and not called after show().

import java.awt.*; import javax.swing.*;
class testDlg {
  static JDlgExt dlg=new JDlgExt();
  public static void main (String args[]) {
    dlg.getContentPane().setLayout(new FlowLayout());
    dlg.setBounds(10,10,200,200);
    dlg.getContentPane().add(new JTextField("text field",12));
    dlg.show();
} }
class JDlgExt extends JDialog
{public void paint(Graphics g) {System.out.println("paint!");}}
Re: overridden JTextField in JDialog
#346
Author: Doychin Bondzhev
Date: Sun, 28 Aug 2005 07:34
20 lines
1971 bytes
try to call super.paint() before your paint code.

Doychin

Hiroshi wrote:
> Hi everyone, a JTextField in a JDialog (or its extended class)ends up with mostly-overridden by paint() for the dialog. Below is the code to demonstrate the problem. When paint() is not included in the dialog class, the field is normally shown, but with it, the field is almost lost. Will you tell me why and how I can avoid this problem? (I do need to include paint() in the dialog class.) Thank you.
> 
> PS paint() is called right after add() and not called after show().
> 
> import java.awt.*; import javax.swing.*;
> class testDlg {
>   static JDlgExt dlg=new JDlgExt();
>   public static void main (String args[]) {
>     dlg.getContentPane().setLayout(new FlowLayout());
>     dlg.setBounds(10,10,200,200);
>     dlg.getContentPane().add(new JTextField("text field",12));
>     dlg.show();
> } }
> class JDlgExt extends JDialog
> {public void paint(Graphics g) {System.out.println("paint!");}}
Re: overridden JTextField in JDialog
#347
Author: Hiroshi
Date: Sun, 28 Aug 2005 22:02
33 lines
2352 bytes
Thank you so much, yes, it worked!

When I was experimenting this paint() in JDialog, I saw the
text field (with blank, although some text was preset to the
control) momentarily shown before it is overridden. So I
thought that after the paint() of the dialog, super.paint()
is causing the overriding...so I wondered how I can stop
super to paint itself...

Anyway thanks again.

Doychin Bondzhev <doychin@dsoft-bg.com> wrote:
>try to call super.paint() before your paint code.
>
>Doychin
>
>Hiroshi wrote:
>> Hi everyone, a JTextField in a JDialog (or its extended class)ends up with mostly-overridden by paint() for the dialog. Below is the code to demonstrate the problem. When paint() is not included in the dialog class, the field is normally shown, but with it, the field is almost lost. Will you tell me why and how I can avoid this problem? (I do need to include paint() in the dialog class.) Thank you.
>> 
>> PS paint() is called right after add() and not called after show().
>> 
>> import java.awt.*; import javax.swing.*;
>> class testDlg {
>>   static JDlgExt dlg=new JDlgExt();
>>   public static void main (String args[]) {
>>     dlg.getContentPane().setLayout(new FlowLayout());
>>     dlg.setBounds(10,10,200,200);
>>     dlg.getContentPane().add(new JTextField("text field",12));
>>     dlg.show();
>> } }
>> class JDlgExt extends JDialog
>> {public void paint(Graphics g) {System.out.println("paint!");}}
Re: overridden JTextField in JDialog
#349
Author: Kevin Dean [TeamB]
Date: Tue, 30 Aug 2005 12:37
28 lines
2204 bytes
Hiroshi wrote:

> Hi everyone, a JTextField in a JDialog (or its extended class)ends up
> with mostly-overridden by paint() for the dialog. Below is the code
> to demonstrate the problem. When paint() is not included in the
> dialog class, the field is normally shown, but with it, the field is
> almost lost. Will you tell me why and how I can avoid this problem?
> (I do need to include paint() in the dialog class.) Thank you.

Unless you're doing something special to the way the dialog (or any
component for that matter) is displayed, you should never have to
override the paint() method.  Furthermore, when overriding the paint()
method, you should call the inherited paint() method which in the
dialog's case ensures that all contained components are painted
properly.

-- 
Kevin Dean [TeamB]
Dolphin Data Development Ltd.
http://www.datadevelopment.com/

NEW WHITEPAPERS
Team Development with JBuilder and Borland Enterprise Server
Securing Borland Enterprise Server
http://www.datadevelopment.com/papers/index.html

Please see Borland's newsgroup guidelines at
http://info.borland.com/newsgroups/guide.html
Re: overridden JTextField in JDialog
#356
Author: Hiroshi Nakata
Date: Mon, 05 Sep 2005 13:18
33 lines
2373 bytes
"Kevin Dean [TeamB]" <NkOdSePaAnM@datadevelopment.com> wrote:
>Hiroshi wrote:
>
>> Hi everyone, a JTextField in a JDialog (or its extended class)ends up
>> with mostly-overridden by paint() for the dialog. Below is the code
>> to demonstrate the problem. When paint() is not included in the
>> dialog class, the field is normally shown, but with it, the field is
>> almost lost. Will you tell me why and how I can avoid this problem?
>> (I do need to include paint() in the dialog class.) Thank you.
>
>Unless you're doing something special to the way the dialog (or any
>component for that matter) is displayed, you should never have to
>override the paint() method.  Furthermore, when overriding the paint()
>method, you should call the inherited paint() method which in the
>dialog's case ensures that all contained components are painted
>properly.
>
Thanks Kevin. Yes, I found a statement in a book saying that paintComponent() should be used instead of paint(). I am going
to try the method instead.

>-- 
>Kevin Dean [TeamB]
>Dolphin Data Development Ltd.
>http://www.datadevelopment.com/
>
>NEW WHITEPAPERS
>Team Development with JBuilder and Borland Enterprise Server
>Securing Borland Enterprise Server
>http://www.datadevelopment.com/papers/index.html
>
>Please see Borland's newsgroup guidelines at
>http://info.borland.com/newsgroups/guide.html
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads