Re: JScrollBar Repaint Question



"mearvk" <mearvk@xxxxxxxxx> wrote in message
news:1167302019.406807.160780@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

public void paintComponent(Graphics g)
{
scrollPane.setSize(getWidth()-30,getHeight()-150);
textField.setSize(getWidth()-30,25);
textField.setLocation(10,getHeight()-130);
send.setLocation(getWidth()/2,textField.getY()+35);
cancel.setLocation(getWidth()/2-110,textField.getY()+35);
super.paintComponent(g);
}

It looks like you're trying to reposition and resize your widgets every
time the JFrame (or whatever the containing component is) needs to be
redrawn. This is generally frowned upon, and the recommended practice is to
use a LayoutManager to position and size the components for you. See this
tutorial for more details:
http://java.sun.com/docs/books/tutorial/uiswing/layout/index.html

- Oliver


.



Relevant Pages

  • Re: [VB5] Can controls resize and position themselves?
    ... Maximized" so at least forms can fit any screen, widgets within forms ... don't seem to have any property so they can resize and/or reposition ...
    (microsoft.public.vb.general.discussion)
  • Re: No app frame for Java application
    ... > of this, I can't resize, reposition, or close an application. ... > versions of RH Linux. ... If you use a JFrame as a top-level component, ...
    (comp.lang.java.gui)
  • Re: [VB5] Can controls resize and position themselves?
    ... Maximized" so at least forms can fit any screen, widgets within forms ... don't seem to have any property so they can resize and/or reposition ...
    (microsoft.public.vb.general.discussion)
  • Re: Enforce minimum window size
    ... >It seems like most layout managers i use allow me to size my window down ... >Do i need to extend Window or Component or JFrame maybe? ... >of resize method? ... >Anybody know any really good open source layout managers available on the web? ...
    (comp.lang.java.programmer)
  • Re: update after modifying the JList
    ... I am able to add the component to the JList lives on the JPanel. ... to resize the JFrame to see the update, if I add the component on the fly. ... I suspect that you are having troubles adding and removing components ...
    (comp.lang.java.gui)