Adding a label on a panel

i have around 7 buttons. Whenever i click on any 1 button, a label with an ImageIcon parameter needs to be displayed on a panel.
when the user clicks the second button, another label with an ImageIcon gets added on the same panel(now the panel has first label+ second label).
These labels can also be moved on the panel using mouse(i have the code to make the label move on the panel).
How do i add these labels on my panel on their respective button clicks?? thanx in advance

i have the following code which adds images on panel and also moves them.you can use any of your own images.i do not know how to add the data structure you suggested....so please help me...thanx in advance
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.datatransfer.*;
import java.io.*;
public class Post extends JFrame implements ActionListener,MouseListener,MouseMotionListener
     Container con;
     MenuBar mbar;
     Menu file,edit,view;
     JPanel p1;
     JPanel dropZone;
     private int xAdjustment;
     private int yAdjustment;
     Component dragComponent;
     int xpoint;
     int ypoint;
     Uml()
     super("Model Transformation Tool");
     con=getContentPane();
     Toolkit kit = Toolkit.getDefaultToolkit();
         final Clipboard clipboard =kit.getSystemClipboard();
     addMouseListener(this);
     addMouseMotionListener(this);
     ImageIcon act = new ImageIcon("..\\uml\\actor4.gif");
     JButton actor = new JButton(act);
     ImageIcon inher = new ImageIcon("..\\uml\\inher.gif");
     JButton inheritance = new JButton(inher);
     actor.setActionCommand("actor");
     actor.addActionListener(this);
     inheritance.setActionCommand("inheritance");
     inheritance.addActionListener(this);
     dropZone = new JPanel();
         dropZone.setBorder(BorderFactory.createLineBorder (Color.blue, 2));
           dropZone.setBackground(Color.WHITE);
     p1=new JPanel();
     con.setLayout(new BorderLayout());
     p1.setLayout(new FlowLayout());
     p1.add(actor);
     p1.add(inheritance);
     con.add(p1,BorderLayout.NORTH);
     con.add(dropZone, BorderLayout.CENTER);
     setVisible(true);
     public void actionPerformed(ActionEvent e)
          String tmp=e.getActionCommand();
          if("actor".equals(tmp))
          Icon icon1 = new ImageIcon("..\\uml\\actorfull.gif");
          JLabel label1=new JLabel(icon1);
          dropZone.add(label1);
          dropZone.revalidate();
          String aname=JOptionPane.showInputDialog("Enter the name of actor");
          JLabel actorname=new JLabel(aname);
          dropZone.add(actorname);
          dropZone.revalidate();
          if("inheritance".equals(tmp))
          Icon icon3 = new ImageIcon("..\\uml\\inher_full.gif");
          JLabel label3=new JLabel(icon3);
          dropZone.add(label3);
          dropZone.revalidate();                    
}//actionPerformed
     public void mousePressed(MouseEvent e)
          Container container =  (Container)e.getSource();
          Component component =  container.findComponentAt(e.getX(), e.getY());
          if (component instanceof JPanel) return;
          dragComponent = component;
          xAdjustment = dragComponent.getLocation().x - e.getX();
          yAdjustment = dragComponent.getLocation().y - e.getY();
     **  Move the component around the panel
     public void mouseDragged(MouseEvent e)
          if (dragComponent == null) return;
          dragComponent.setLocation(e.getX() + xAdjustment, e.getY() + yAdjustment);
     **  Deselect the component
     public void mouseReleased(MouseEvent e)
          dragComponent = null;
     public void mouseClicked(MouseEvent e) {}
     public void mouseMoved(MouseEvent e) {}
     public void mouseEntered(MouseEvent e) {}
     public void mouseExited(MouseEvent e) {}
     public static void main(String args[])
     Toolkit kit = Toolkit.getDefaultToolkit();
     Dimension screenSize = kit.getScreenSize();
     int screenWidth = screenSize.width;
     int screenHeight = screenSize.height;
     Uml obj=new Uml();     
     obj.setBounds(0, 0, screenWidth, screenHeight-29);
     obj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}//class

Similar Messages

  • Labels in my Panel

    I'm sorry that I couldn't figure this out from the search. I tried a few things but none seemed to work.
    I have a panel that contains labels. The labels represent objects alive in my system. The Frame watches these objects and updates every second.
    I start the panel empty except for a static label at the top that says "objects".
    in each loop, I collect object names in an array and create labels for each. I want to replace the current panel content with the new labels. I have tried re instantiating the panel, re writing the panel's paint method to add new labels, but my panel remains looking the same. Can anyone help?
    Thanks

    Using awt Panels. I didn't want later users to have to have a higher version of java. I'm not married to the version though. Below is the code that I am using...
      // Creates the userDisplay panel
      // UserDisplay is defined in the Frame
        public void createUserDisplay(ArrayList users){
          users = users==null?new ArrayList():users;
          if(userDisplay != null){
            userDisplay.removeAll();
          }else{
            userDisplay = new Panel();
          int labelHeight = 8;
          int labelWidth = 24;
          userDisplay.setSize(labelWidth,0);
          userDisplay.setBackground(Color.white);
          userDisplay.setLayout(new java.awt.GridLayout(0,1));
          Label usersHeader = new Label();
          usersHeader.setSize(labelWidth,labelHeight);
          usersHeader.setBackground(Color.white);
          usersHeader.setFont(BIG);
          usersHeader.setText("USERS");
          usersHeader.setBounds(0,labelWidth,labelHeight,labelWidth);
          userDisplay.add(usersHeader);
          for(int a = 0; a < users.size(); a++){
            Label L = new Label();
            L.setFont(normal);
            L.setBounds(0,labelWidth + (a * labelHeight),labelHeight,labelWidth);
            L.setBackground(
              ((SimpleChat.User)users.get(a)).status == 1
              Color.yellow
              Color.white
            L.setSize(labelWidth,labelHeight);
            L.setText(((SimpleChat.User)users.get(a)).name);
            userDisplay.add(L);
            System.out.println("Added " + L.getText());
          }

  • Adding data labels to column graph

    I work in the financial industry and I have to add data labels to all bars that appear in my ten year performance graphs (see http://fundinvestor.calamos.com/ClosedEndFunds/CEFund.aspx?name=CHI under the "Performance" tab as an example). Is there a script that can do this? I saw there's this technique that Adobe offers for column totals: http://livedocs.adobe.com/en_US/Illustrator/13.0/help.html?content=WS714a382cdf7d304e7e07d 0100196cbc5f-619e.html but that's not working. What am I doing wrong? Adding data labels to bars is ridiculously simple in Excel, why can't I find the way to do it easily in Illustrator?

    http://help.adobe.com/en_US/Illustrator/14.0/WS714a382cdf7d304e7e07d0100196cbc5f-619ea.htm l
    That should do the trick.
    Mylenium

  • On which router B bit is added in Label?

    On which router B bit is added in Label?

    Ashwin,
    I hope you are referring "Bottom of stack" bit?. If yes, please see below,
    When LER (Label Edge Router) receives the IP packet and if the egress is LSP based, it pushes one or more labels. The number of label to be pushed depends on the service and the transport path. For example, when the SP is providing L2/L3 VPN service, the LER will push 2 labels. The bottom label to identify the service and the top label to identify the remote edge router. If there is TE tunnel established along the path and if the TE is not end-to-end, you may see 3 labels pushed. 
    When LER pushes the labels, it set the S bit as 1 in the bottom label. This is required so the ASIC can understand if the ethertype is to be set to 0800 (IP packet) or 8847 (MPLS packet).
    -Nagendra

  • Find a component with his id ? (ex find a Label in a Panel with the Label's id)

    Hello, I need to find a children component with his id (so without getchildat ou byname methods)
    ex :
    <mx:Panel id="panel1" x="10" y="10" title="PANEL 1" width="400" height="300">     
    <mx:Label id="label1" x="15" y="15" text="label 1 dans panel 1" />
    <mx:Panel id="panel2" x="70" y="50" title="panel 2 ds panel 1" width="100" height="50">
    <mx:Label id="label2" x="25" y="25" text="label 2 dans panel 2" />                    
    </mx:Panel>                    
    </mx:Panel>
    with id=label2 or id=panel2 I would like have the Label or Panel, without having to look in children of children
    because there is only one single id in application I think it's possible, but don't find how
    think's in advance for your ideas !
    Dave

    hello atta707, think you for you help !
    but I need it to find components I create with my methods createLabel and createPanel
    > I have found this[id]
    it work good for components who are first in application
    but it doesn't find components who are created after
    for example, with :
    <mx:Panel id="firstpanel"></mx:Panel>
    this[firstpanel] work
    but if I create a new panel in the first panel :
    newPanel = new Panel();
    this[firstpanel].addChild(newPanel)
    this[idNewPanel] doesn't work !
    so it seems when you use addChild it add the component in screen and children tree
    BUT not in this[id]
    and if I try
    this[idNewPanel]=newPanel it doesn't work
    so I need a method to find NEW components by their id
    or to oblige this[id] to register the new components created
    any idea ? >

  • Adding Custom Labels Missing for Contact Numbers After Upgrading to iOS 8.0 and issue still exists on iOS 8.1

    I noticed that after upgrading to iOS 8.0 on my iPhone 5s, adding custom labels for contact numbers got removed. It still exists on iOS 8.1 as well. Is there someone who is facing a similar issue or can someone help me how to get that back. Any suggestions would be greatly appreciated.
    Thank you.

    Hi Yugendra,
    Thanks for visiting Apple Support Communities.
    I have good news. You can still choose a custom label in Contacts on iOS 8. The option should be below "Other" in the list of labels when editing a contact. This information is found in the iOS 8 user guide:
    Contacts at a glance - iPhone
    Change a label. If a field has the wrong label, such as Home instead of Work, tap Edit. Then tap the label and choose one from the list, or tap Add Custom Label to create one of your own.
    Best Regards,
    Jeremy

  • Search text in all the labels in a panel (like control-F)

    hi,
    I have a Panel where I configure some preferences of the application. There ara about 200 preferences. (a preference is a JLabel plus a textfield/combobox/checkbox)
    I would like to know if someone has implemented something like control-F in browsers. The search should go through all the labels and highlight the label(s) that contain the text.
    thanks.

    You can use getComponents() method to get all components added to the Panel. Iterate through the array and check whether the current one is a JLabel instance. Then check JLabel's text and compare with the search string. If necessary label found highlight it (e.g. by changing text color or adding/removing colored line border). Then you can use the JLabel's bounds to make it visible in a scroll (if any).

  • Moving a label in a panel using keyboard

    Hello,
    I have a component in a panel. The panel has got vertical and horizontal scroll bars. I need to move the label using the arrow keys on the key board. It only works for VK_LEFT AND VK_UP and when I try to move the label DOWN or RIGHT, the scroll bars move. I need to hold the CTRL+ARROW KEY to get the functionality.
    How do I over come this type of error? i.e I dont want to hold the CTRL key and I want only the arrow keys to do the work.
    Thanks

    Hi,
    Can you please correct this code? I can move the label UP and LEFT but when I move down or right, the scroll pane is moving. Just Click on the label and then try to move the label. Any ideas would help.
    Thanks
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class MoveLabel extends JFrame
         JLabel label;
         public MoveLabel()
              label = new JLabel(new ImageIcon("copy.gif"));
              label.setBounds(20,30,16,19);
              label.addKeyListener(new KeyAdapter()
                   public void keyPressed(KeyEvent ke)
                        if(ke.getKeyCode() == KeyEvent.VK_DOWN)
                             label.setLocation(label.getX(),label.getY()+1);
                             repaint();
                        if(ke.getKeyCode() == KeyEvent.VK_UP)
                             label.setLocation(label.getX(),label.getY()-1);
                             repaint();
                        if(ke.getKeyCode() == KeyEvent.VK_LEFT)
                             label.setLocation(label.getX()-1,label.getY());
                             repaint();
                        if(ke.getKeyCode() == KeyEvent.VK_RIGHT)
                             label.setLocation(label.getX()+1,label.getY());
                             repaint();
              label.addMouseListener(new MouseAdapter()
                   public void mouseClicked(MouseEvent me)
                         if(me.getClickCount() == 1)
                              boolean dd = label.isOptimizedDrawingEnabled();
                              boolean ff = label.requestFocusInWindow();
                              repaint();
              JPanel p = new JPanel();
              p.setPreferredSize(new Dimension(2000,1000));
              p.setLayout(null);
              p.add(label);
              JScrollPane js = new JScrollPane(p);
              getContentPane().add(js);
         public static void main(String args[])
              MoveLabel frame = new MoveLabel();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.setSize(300,300);
              frame.setVisible(true);
    }

  • Adding a scrollbar to a panel

    this seems like it should be a no brainer.  I am dynamically adding elements to a panel, and sometimes there is too much stuff and the size of the window gets enormous.  I would like a fixed windoe size, and if the elements in the panel spill over the edge, give me a scrollbar to see those items that arent visible.
    this is not the first time I have set out to solve this problem...is there really no way to have a scrolling panel?  the javascript tools guide speaks of a scrollbar element, but it is not documented very well and does not appear to do much of anything.
    Mike Cardeiro

    Continued here:
    http://forum.java.sun.com/thread.jspa?threadID=5146140
    OP, don't you think one thread's enough?

  • Drop Icons or labels into a panel

    I am trying to build an applet where labels with icons are draggable and can be dropped in a panel at the bottom of an applet. Eventually, depending on the shapes of the icons dropped, that shape will be painted into a canvas on the same applet. But for now I need to figure out a way to enable the drop capability to a swing container. Preferably, a jEditorPane. Is that possible?
    Anyone?

    [url http://java.sun.com/developer/JDCTechTips/2003/tt0318.html#1]DRAGGING TEXT AND IMAGES WITH SWING

  • Globally adding "custom" labels to Address Book

    Any way to do it?
    I understand how labels work now (I think); that a custom label is only saved with the contact itself.
    What I want to do is to add a label (e.g.: "Skype" to the phone numbers) that I can choose in existing contacts without having to retype it every time. For new contacts, I can change the template to help a bit, but for existing contacts, it seems there is no way but to type it every time.

    you add add it to the AB template in AB preferences->template. then it will automatically appear in all new vcards you create. but for some reason it won't be automatically added to existing contacts. that seems a bug to me.

  • Adding more labels?

    Good afternoon everyone.
    So I want to have more labels than the 8 Premiere Pro gives me but cannot find a way to add any more.  Are there options to do so that I'm simply not seeing nor finding?

    I want the same and can't see that it is currently possible.
    I've added a feature request for this.

  • Tasks/Reminders added from Outlook (iCloud Control Panel synced) can't be checked off as completed on iOS

    I have Outlook on my PC, and can interact with the iOS reminders/tasks through syncing with the iCloud Control Panel. However, if I add a task/reminder this way I have been unable to mark the reminder as complete on my iOS devices (iPhone and iPad). The reminders show up, but clicking on the circle to the left of the task just updates the UI (fills in a circle). If you exit the reminders app or Today screen and go back, the task still remains uncompleted in the list.
    Has anyone else seen this? Right now, from iOS, I can only get rid of the reminders by deleting (instead of completing) them ... which is not ideal.
    Current Configuration:
    iPhone 5s with iOS 7.1
    iPad Air with iOS 7.1
    Outlook 2010 on Windows 7 with iCloud Control Panel 3.1

    Hello desert_dweller5,
    It sounds like you art trying to access a Shared Photo Stream, but you do not have one of the devices to enable your Apple ID as an iCloud account.  The following article provides information on how Shared Photo Streams work:
    iCloud: Photo Stream FAQ
    http://support.apple.com/kb/HT4486
    The article states that for privately Shared Photo Streams to work, the recipient will not only have to have an Apple ID, but it will have to be an iCloud account:
    Friends and family with iCloud accounts can view your photos in the Photos app on any device using iOS 6 or later; on a Mac in iPhoto 9.4 or Aperture 3.4 or later; on a Windows PC with Windows Vista or later and iCloud Control Panel 2.0 or later installed; or on a second generation or later Apple TV with software version 5.1 or later installed. They can also view your photos on the web if you enable Public Website in the settings or options for your Shared Photo Stream.
    Since you do not have an iCloud account and just and Apple ID, your friend can share the photo stream as a public website so that you can view it, as stated in the same article: 
    Can I share with people who don't have an iCloud account?
    Yes. If you enable Public Website in the settings or options for your shared photo stream your photos will be published to a website that anyone can view in an up-to-date web browser.
    To be able to change an Apple ID to an iCloud account, you would need an iPhone, iPad, or iPod touch with iOS 5 or later or a Mac with OS X Lion v10.7.4 or later as stated in the following article:
    Creating an iCloud account: Frequently Asked Questions
    http://support.apple.com/kb/HT4436
    Best,
    Sheila M.

  • Adding dynamic content to accordion panels

    Hello,
    and thank you in advance for any help.
    I need to make a new web page for my girlfriend. She's a
    photographer which means she needs to update her page pretty often.
    The usual small systems however were way too complicated for her.
    After seeing Spry, I decided to use it, along with Relay
    which gives an easy option for updating content. So here's my plan:
    - I install Relay so she has sort of a back-end to update her
    pictures.
    - I have a php script which reads out the directories and
    makes an xml file to use with spry.
    However I find it very difficult to understand how I should
    use this xml file. Additionally, she wants to have the accordion
    panels, so I have to put the code (probably the same code with only
    a different xml filename for each directory) into every panel.
    Could anybody help me with that? Please note that I haven't
    started anything yet and am right now trying stuff locally.
    Thank you again.
    Mete

    Hello again,
    I'll try to describe the case once again, this time more
    clearly:
    - I will install Relay onmy server to enable uploading
    pictures. Relay stores the upload pictures in different directories
    which are created by the user and the path to each directory is
    known.
    - A PHP-Script reads out the content of these directories
    (names, paths etc) and gives a list as an XML-File.
    What I want to do is:
    Make an HTML-Page and use Spry Accordion Panels in it.
    Let's say I have 5 panels. Each panel (in itself) shall use
    the XML-file (one file per directory) to display the pictures. The
    styling will be made by using the CSS.
    My problem is:
    I just can not figure out how to use the regions etc in Spry.
    I have to admit that so easy it is to use, it 's also pretty
    difficult to understand the logic behind it for non-skilled users
    (especially for those who do not have Dreamweaver etc). I can't
    find the answers to my questions like: Why do the datasets get the
    prefix "dsXXXX"?
    I only want to read the XML-File and display these pictures
    in an Accordion Panel without floating, which means it has to
    scroll left and right.
    I hope this makes it easier to understand :)
    Thank you once again!
    Mete

  • Adding different images to different panels

    If I am having a class which is extending Applet not JApplet and in that I am having CardLayout with 4 different panels. If I want to add 4 different images 2 these Panels what is the solution? Can anyone please help?

    sorry
    myPanel p1, p2, p3, p4;
    class myPanel extends Panel
    Image image;
    public myPanel(Image img)
    image = img;
    public void paint (Graphics g)
    if (image == null)
    return;
    g.drawImage(image, 0, 0, this);
    }

Maybe you are looking for