Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #2531

repaint issue when compne

From "Chanchal" <chanchal@THRWHITE.remove-dii-this>
Subject repaint issue when compne
Message-ID <1190705690.856528.83200@g4g2000hsf.googlegroups.com> (permalink)
Newsgroups comp.lang.java.gui
Date 2011-04-27 15:39 +0000
Organization TDS.net

Show all headers | View raw


  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

Back to comp.lang.java.gui | Previous | NextNext in thread | Find similar | Unroll thread


Thread

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

csiph-web