Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #2531 > 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 | 4 — 3 participants |
Back to article view | Back to comp.lang.java.gui
repaint issue when compne "Chanchal" <chanchal@THRWHITE.remove-dii-this> - 2011-04-27 15:39 +0000
Re: repaint issue when co "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> - 2011-04-27 15:39 +0000
Re: repaint issue when co "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> - 2011-04-27 15:39 +0000
Re: repaint issue when co "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 issue when compne |
| Message-ID | <1190705690.856528.83200@g4g2000hsf.googlegroups.com> |
To: comp.lang.java.gui
Hi All,
I have a component "JPResourceBox" which extends JPanel
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
public class JPResourceBox extends javax.swing.JPanel {
/** Creates new form JPResourceBox */
public JPResourceBox(JPWorkspacePanel parent) {
initComponents();
}
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
setLayout(new java.awt.BorderLayout());
setBorder(javax.swing.BorderFactory.createEtchedBorder());
jLabel1.setText("jLabel1");
add(jLabel1, java.awt.BorderLayout.CENTER);
}
private javax.swing.JLabel jLabel1;
public void setText(String buttonText){
this.jLabel1.setText(buttonText);
}
}
I am adding instances of JPResourceBox to a JFrame programatically on
a button click
public class NewJFrame extends javax.swing.JFrame {
private javax.swing.JButton jButton1;
public NewJFrame() {
initComponents();
}
private void initComponents() {
jButton1 = new javax.swing.JButton();
getContentPane().setLayout(null);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent
evt) {
jButton1ActionPerformed(evt);
}
});
getContentPane().add(jButton1);
jButton1.setBounds(160, 210, 75, 23);
pack();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent
evt) {
JPResourceBox jp = new JPResourceBox(null);
jp.setBounds(50,50,50,50);
add(jp);
repaint();
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
}
When i click the button, the JPResourceBox instance is getting added
to the JFrame and is visible. But the text in the JLabel inside
JPResourceBox instance is not visible. If the JFrame is resized, the
text in JLablel is getting displayed.
Kindly advice on how the text in JLabel can be made to be displayed
when JPResourceBox instance is added to the JFrame.
Thanks and Regards
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 | "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:39 +0000 |
| Subject | Re: repaint issue when co |
| Message-ID | <apfhf39ipnja7rordlsqh23ifcb6rern15@4ax.com> |
| In reply to | #2531 |
To: comp.lang.java.gui On Tue, 25 Sep 2007 00:34:50 -0700, Chanchal <chanchal.jacob@gmail.com> wrote, quoted or indirectly quoted someone who said : >When i click the button, the JPResourceBox instance is getting added >to the JFrame and is visible. But the text in the JLabel inside >JPResourceBox instance is not visible. If the JFrame is resized, the >text in JLablel is getting displayed. After you add a Component, you must do a validate() to let the components jostle about and let the layout manager determine their new sizes and positions. This does not happen automatically, to avoid recalculating after every add in a continuous stream of adds. It would just cause annoying flicker. -- Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com --- * 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 | "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:39 +0000 |
| Subject | Re: repaint issue when co |
| Message-ID | <rtfhf3djjj8b1tm3q7fc9u2mavvspip49h@4ax.com> |
| In reply to | #2533 |
To: comp.lang.java.gui On Tue, 25 Sep 2007 07:57:30 GMT, Roedy Green <see_website@mindprod.com.invalid> wrote, quoted or indirectly quoted someone who said : >After you add a Component, you must do a validate() to let the >components jostle about and let the layout manager determine their new >sizes and positions. > >This does not happen automatically, to avoid recalculating after every >add in a continuous stream of adds. It would just cause annoying >flicker. see http://mindprod.com/jgloss/validate.html http://mindprod.com/jgloss/repaint.html -- Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com --- * 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 issue when co |
| Message-ID | <78bcbd0f9bac6@uwe> |
| In reply to | #2531 |
To: comp.lang.java.gui Chanchal wrote: >Hi All, > >I have a component "JPResourceBox" which extends JPanel What about JPWorkspacePanel? I had to refactor that to a JPanel before I could get this code to work, and then I saw no 'flicker'. OTOH, I think the root cause of that problem (as well as potentially others you have not yet seen) is code like.. .. > jButton1.setBounds(160, 210, 75, 23); .. > jp.setBounds(50,50,50,50); Using these kind of conbstructs, you can expect problems. Learn how to use layouts, and I am betting the problem will vanish. <http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html> And as an aside, please consider posting SSCCE's, to help others to help you. An SSCCE would either have removed the reference to JPWorkspacePanel, or added the code, and demoted JPResourceBox to 'default' access. To make SSCCE's short (the first 'S') it is best to add 'package imports'* at the top of the code, then drop use of the fully qualified name of each widget used. * That makes for a good SSCCE, not 'good production code' - the two are different things. -- 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