Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #2567 > unrolled thread
| Started by | "Chanchal" <chanchal@THRWHITE.remove-dii-this> |
|---|---|
| First post | 2011-04-27 15:39 +0000 |
| Last post | 2011-04-27 15:39 +0000 |
| Articles | 5 — 2 participants |
Back to article view | Back to comp.lang.java.gui
Repaint not happening whe "Chanchal" <chanchal@THRWHITE.remove-dii-this> - 2011-04-27 15:39 +0000
Re: Repaint not happening "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:39 +0000
Re: Repaint not happening "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:39 +0000
Re: Repaint not happening "Chanchal" <chanchal@THRWHITE.remove-dii-this> - 2011-04-27 15:39 +0000
Re: Repaint not happening "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:39 +0000
| From | "Chanchal" <chanchal@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:39 +0000 |
| Subject | Repaint not happening whe |
| Message-ID | <1190963487.718268.76360@d55g2000hsg.googlegroups.com> |
To: comp.lang.java.gui
Hi All,
I have five classes MyFrame, MyContainerPanel,MyPanel, MyButton and
MyLine.
MyFrame contains MyContainerPanel, MyContainerPanel contains MyPanel
and MyPanel
contains MyButton.
Constructor in MyButton takes an object of MyContainerPanel. So when
MyPanel is created an instance of MyContainerPanel is passed, which is
in turn passed to the contained MyButton instance.
MyButton has an inner class ML which extends MouseInputAdapter and the
mouseClicked() method is defined.
Now when MyButton is clicked, a function addLine() in MyContainerPanel
should be called, which will add a MyLine instance to the contaied
MyPanel instance. My problem is that when this add() is called, the
overrideen paintComponent() method in MyLine is not getting called.
Please find the code..
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.event.*;
public class MyButton extends JPanel {
MyContainerPanel mp;
public MyButton(MyContainerPanel mp){
this.mp = mp;
addMouseListener(new ML());
setBorder(javax.swing.BorderFactory.createLineBorder(new
java.awt.Color(0, 0, 0)));
}
class ML extends MouseInputAdapter{
public void mouseClicked(MouseEvent e){
System.out.println("MB CLICKED");
mp.addLine();
}
}
}
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class MyPanel extends JPanel{
MyContainerPanel mp;
public MyPanel(MyContainerPanel mp){
System.out.println("MyPanel constructor");
MyButton mb = new MyButton(mp);
setLayout(null);
mb.setBounds(10,10,100,50);
add(mb);
}
}
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class MyContainerPanel extends JPanel{
MyPanel mp;
public MyContainerPanel(){
mp = new MyPanel(this);
setLayout(new BorderLayout());
add(mp);
}
public void addLine(){
MyLine ml = new MyLine();
mp.add(ml);
mp.validate();
}
}
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class MyFrame extends JFrame{
public MyFrame(){
}
public static void main(String[] args){
MyFrame mf = new MyFrame();
mf.add(new MyContainerPanel());
mf.setSize(400,300);
mf.setVisible(true);
}
}
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Graphics;
import java.awt.Color;
public class MyLine extends JPanel{
protected void paintComponent(Graphics g){
System.out.println("Painting MyLine");
}
}
Kindly advice what needs to be done so that the paintComponent() in
MyLine instance is called, when it is added to the MyPanel instance.
Thanks in advance
Chanchal
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [next] | [standalone]
| From | "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:39 +0000 |
| Subject | Re: Repaint not happening |
| Message-ID | <78e1fc38b3664@uwe> |
| In reply to | #2567 |
To: comp.lang.java.gui Chanchal wrote: .. >I have five classes ... Which can all be enclosed in a single SSCCE. Please *read* the document. After wrestling this into a form that is compilable in a single file, then trying to sort the mess, I noticed this.. .. setLayout(null); .. Which makes me wonder. a) Why you are ignoring my advice? .and more importantly .. b) Why I should spend (or waste) any more time trying to help you? -- Andrew Thompson http://www.athompson.info/andrew/ Message posted via JavaKB.com http://www.javakb.com/Uwe/Forums.aspx/java-gui/200709/1 --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:39 +0000 |
| Subject | Re: Repaint not happening |
| Message-ID | <1191054365.039502.168390@r29g2000hsg.googlegroups.com> |
| In reply to | #2567 |
To: comp.lang.java.gui On Sep 28, 5:11 pm, Chanchal <chanchal.ja...@gmail.com> wrote: Gmail huh? since I posted a reply a while ago, and it does not appear at GG yet, I will (hopefully) progress this matter by linking to another web representation of my reply. http://www.javakb.com/Uwe/Forum.aspx/java-gui/7356/Repaint-not-happening-when-compnent-added-to-panel-progrmatically#78e1fc38b3664uwe Andrew T. --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Chanchal" <chanchal@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:39 +0000 |
| Subject | Re: Repaint not happening |
| Message-ID | <1191076536.433438.22020@d55g2000hsg.googlegroups.com> |
| In reply to | #2569 |
To: comp.lang.java.gui Dear Mr. Thompson, It is not that i'm ignoring your advice. I pretty much appreciate that. i know that the porblem here is again setLayout(null). But i'm a bit helpless here. It could be a design flaw, but i'm left here with five classes which are represented by the five classes in my original post. I'm having to develop this UI, but situation here is that i cannot go and change the design. Also the added components needs to come in the specified places, not in a region as defined by the BorderLayout or at an available place as decided by the FlowLoayout. Using GridLayout or GridBagLayout turns out to be too complex. i'm forced to use null layout. i do not have a choice as far as the design of this UI is considered. So all i can do is to find out how i can fit things into this may-be-bad design. Again if you are able to give some suggestion on how this can be implemented in this given scenario,rather than thinking that you are wasting your time, i'd appreciate it. Thanks again Chanchal --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:39 +0000 |
| Subject | Re: Repaint not happening |
| Message-ID | <78f458757ebcc@uwe> |
| In reply to | #2570 |
To: comp.lang.java.gui Chanchal wrote: .. >It is not that i'm ignoring your advice. Have you done the layout tutorial yet? >..I pretty much appreciate >that. i know that the porblem here is again setLayout(null). But i'm a >bit helpless here. It could be a design flaw, but i'm left here with >five classes which are represented by the five classes in my original >post. I'm having to develop this UI, but situation here is that i >cannot go and change the design. Yes you can. If you had done the layout tutorial, that much should be obvious. >..Also the added components needs to >come in the specified places, .. Which is what layouts do. The only reason my versions of the layouts differed from yours, is that I did not take much care to place them 'pixel by pixel' exactly as you had them, that was left as an exercise for you. 'Batteries not included'. And while we are on 'specified places', I will point out that null layout/exact positioning GUI's might well fail under a different PLAF or Java version, on screens of different resolution or size, on different platforms, with a different default font size, or.. any number of other reasons. Exact pixel positioning just does not make any sense in a language defined to be X-plat - unless you cover all of the things mentioned above. Once your GUI has tacked every aspect of that down, you might as well have put that logic into a layout manager. Using the inbuilt layouts might give you a good start at understanding how to make a custom layout manager. >..not in a region as defined by the >BorderLayout or at an available place as decided by the FlowLoayout. Adjust the borders or insets. Your comment about how the FlowLayout of an earlier example did not meet your exact requirements is a good indication that you had not checked the JavaDocs. They are invaluable for this stuff, and programmers need to read a lot of documentation if they expect to be successful. Asking people on usenet newsgroups to fix the basic problems with an already very broken null layout, is no substitute. >Using GridLayout or GridBagLayout turns out to be too complex. i'm >forced to use null layout. No, you just need to put the effort in to learning how to use them. If you really cannot figure how best to layout any particular GUI - try describing it in either a text diagram (good for usenet, but not the sort of precise definitions that you seem to want), or an actual (crude or otherwise) drawing - which cannot be posted to this usenet group, but can be shown to others via URL. >..i do not have a choice as far as the design >of this UI is considered. So all i can do is to find out how i can fit >things into this may-be-bad design. Again if you are able to give some >suggestion on how this can be implemented in this given >scenario,rather than thinking that you are wasting your time, i'd >appreciate it. Layouts. By the way. You seem to be putting more time and effort into your excuses, than you are into doing the layout tutorial, or otherwise learning how to use them. That is not time well spent. -- Andrew Thompson http://www.athompson.info/andrew/ Message posted via JavaKB.com http://www.javakb.com/Uwe/Forums.aspx/java-gui/200709/1 --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.gui
csiph-web