Putting a Jlabel in a specific place in JPanel

Hi,
I have created a JApplet where I fill it up with some JPanels. Inside a JPanel i want to put some Jlabels on a specific place. However, it doesn't work.
Whenever i try to put a setLayout(null), the application doesn't show my modifications. If don't use this command, the modification are loaded.
I don't know what happes with this layout. Is it a problem of layout or a problem of JPanel references?
          canvas = new AVLTreeAnimation();
          //canvas.setLayout(null);
          JLabel label = new JLabel("trestadf");
          label.setLocation(10, 10);          
          canvas.add(label);
          canvas.setBorder(new TitledBorder(null,"AVL-Tree Animation",
                    TitledBorder.LEFT, TitledBorder.TOP));
          canvas.repaint();          
          return canvas;thanks for your help

man, this same problem's come up a lot this week.
If you set the layout to null, you have to set the size and the location, not just the location. All components have a size of 0 x 0 initially.

Similar Messages

  • Putting a label in a specific place

    I have a small ImageIcon that I'd like to display in a specific location in a JPanel.
    I discovered you can't paint an ImageIcon directly onto a JPanel (or can you???). So I added the ImageIcon to a JLabel, then added that to my JPanel.
    OK, that worked. Trouble is, I want to be able to move that label around on the panel -- to be able to set and reset its location based on user input. But I can't find a way to do that. If I try to at least set the location of the JLabel in the upper left-hand corner of the JPanel, I can't even do that. I tried setLocation(), but it doesn't seem to work. I'm guessing that when I call setLocation(), the method is only affecting the placement of the graphic in the JLabel itself, but not the placement of the JLabel in the JPanel.
    So do any of you out there have suggestions for how I could do this? I'm wondering if I shouldn't just create a large JLabel that covers the whole panel, and then use setLocation() to move the ImageIcon around on the label, rather than try to move the label around on the panel. Does that sound like a reasonable solution?
    The original suggestion was to custom make a paint() method to use on a Canvas, but I really prefer using the Swing JComponents if I can.
    Thanks for any help!

    Here is an example of code that moves a JLabel within a JFrame.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    public class LabelMover extends JPanel {
        JLabel myLabel;
        /** Creates a new instance of LabelMover */
        public LabelMover() {
         addMouseMotionListener(new MyMouseMotionAdapter2());
         myLabel = new JLabel("this is an example");
         myLabel.setOpaque(true);
         myLabel.setBackground(Color.YELLOW);
         myLabel.setBorder(BorderFactory.createLineBorder(Color.black));
         add(myLabel);
        public class MyMouseMotionAdapter2 extends MouseMotionAdapter {
         public void mouseMoved(MouseEvent e) {
             myLabel.setLocation(e.getX(), e.getY());
        public static void makeGUI() {
         JFrame myFrame = new JFrame();
         myFrame.setBounds(0, 0, 300, 300);
         myFrame.getContentPane().setLayout(null);
         LabelMover myContent = new LabelMover();
         myContent.setOpaque(true);
         myContent.setBackground(Color.WHITE);
         myFrame.setContentPane(myContent);
         myFrame.setVisible(true);
         * @param args the command line arguments
        public static void main(String[] args) {
         javax.swing.SwingUtilities.invokeLater(new Runnable() {
             public void run() {
              makeGUI();
    }

  • Is there a way to put the cursor at a specific location in a RichTextBox?

    Is there a way to put the cursor at a specific location in a RichTextBox?
    The following code places the cursor at the start of a RichTextBox:
        RichTextBox RTbx
        RTbx.Focus();
        TextPointer tp = RTbx.CaretPosition;
        tp = tp.DocumentStart;
        RTbx.CaretPosition = tp;
    Not sure how to place it at a specific location other than start and end.
    The RichTextBox has contents.  At this point in the code, I do know the specific "word" in the contents, as well as the position (number of chars) where that word is located.  I just need to programmatically place the cursor at that location.
    bhs67

    Oh sorry, I see I missed something out my original reply.
    I have markup:
    <Grid>
    <RichTextBox Name="rtb">
    <FlowDocument>
    <Paragraph >This is the first paragraph</Paragraph>
    <Paragraph >TSecond paragraph is here</Paragraph>
    </FlowDocument>
    </RichTextBox>
    </Grid>
    Code - this is the window contentrendered event
    private void Window_ContentRendered(object sender, EventArgs e)
    rtb.Focus();
    // TextPointer moveTo = rtb.CaretPosition.GetNextInsertionPosition(LogicalDirection.Forward);
    TextPointer moveTo = rtb.CaretPosition.GetPositionAtOffset(9, LogicalDirection.Forward);
    if (moveTo != null)
    rtb.CaretPosition = moveTo;
    I see the cursor between the t and he of the second "the".
    Note that there are numerous other options such as the commented out line.
    Hope that helps.
    Recent Technet articles: Property List Editing;
    Dynamic XAML

  • I am wanting to add picture and designs to my form how do I place it in a specific place on my form?

    I am wanting to add picture and designs to my form how do I place it in a specific place on my form?

    Currently we only support one field/item on a line. We are working on adding a feature that allows you to put multiple fields/items on a single line. We hope to have that out in a few months.
    Randy

  • TS3297 I have an iPhone and recently bought an iPod 4 touch what l am using the same apple ID for. The iPod won't let me download songs from iTunes it is asking me security questions which I don't think I have put answers to in the first place.

    I have an iPhone and recently bought an iPod 4 touch what l am using the same apple ID for. The iPod won't let me download songs from iTunes it is asking me security questions which I don't think I have put answers to in the first place, because of this it won't let me buy any songs on iTunes

    It's probably asking you to verify the security code found on the back of your credit card.
    Regards.

  • How can I put a time delay between specific events in a while loop?

    How can I put a time delay between specific events within the same while loop? I'm already using the "wait" command to control the overall loop iteration speed. But I want to time the individual events as well.

    Hi Jesse,
    You can use a flat sequence. In each box you can put your individual events and attached wait.
    Don't forget to reduce your total loop time of the time you added in the individual sequences.
    Doc-Doc
    Doc-Doc
    http://www.machinevision.ch
    http://visionindustrielle.ch
    Please take time to rate this answer

  • How do I link to a specific place on a "different" page?

    I understand how a Named Anchor works on a given page. How do I click a link on one page, and go to a specific place on another page? Can that be done?
    Thanks!

    Same page anchor:
    <a href ="#anchoronthispage">
    Different page anchor:
    <a href="anotherpage.html#anotheranchor">

  • External hyperlink to specific place in a PDF file?

    Is it possible to have an external hyperlink on a webpage to a specific place in a PDF file? If so, how is it done? I would be creating the PDF file in InDesign. Thanks

    Great...many thanks
    Mark

  • Hi thee.  As logical as I can be.  I export a file back into my folder as a PSD.  I then export that file to PS.  Work on it, save and return it to LR.  The file goes to the bottom of the folder from where I have to put it back in the original place, taki

    Hi thee.  As logical as I can be.  I export a file back into my folder as a PSD.  I then export that file to PS.  Work on it, save and return it to LR.  The file goes to the bottom of the folder from where I have to put it back in the original place, taking time and driving me slightly mad.  Why does the file not go back to where it came from please?  Thanks  Tim

    Umm, but this folder is an amalgam of two cameras and five cards, and I want them in capture order!  Thanks for trying though Jim.
    Cheers
    Tim

  • I want to link to a specific place within a document from Captivate4

    Hi all,
    I want to link to a specific place within a document from Captivate4.
    I have no trouble linking to the beginning of a document; however I want to be able to link to a specific chapter/area of a document I am creating. My plan is that as people progress through the e-learning they can link back to the electronic manual I am creating from where they left off.
    I have a workaround of creating separate documents and linking to them, but this is time consuming and messy.
    Does anyone have any ideas of what I can do; I have looked around the forums and, unless I am blind, can't find anything like I am looking for.
    Cheers
    thedarf

    Hi there
    What type of document are you trying to link to? PDF? Word Doc?
    Cheers... Rick
    Helpful and Handy Links
    Captivate Wish Form/Bug Reporting Form
    Adobe Certified Captivate Training
    SorcerStone Blog
    Captivate eBooks

  • Linking to specific place in newsletter

    Hello:
    I am trying to find out how to link from an email digest to a specific place in our newsletter. The newsletter page will have several stories on it, which can be read by scrolling down. I would like to email a digest with brief synopsis of the stories, which will link back to the exact story on the newsletter page, not just the newsletter page itself.
    Thanks for any help you can offer.
    Chip Mitchell

    You could use anchors, then set the links to those specific anchors.
    Unless I'm missing something.

  • How can I put a selected picture in multiple places in slideshow

    As the heading states: how can I put a selected picture in multiple places in slideshow
    There is a slideshow with 50 pics. I want to use one of these pics in several places, in the front, middle, middle end and then the end.
    How can I place this pic in multiple locations in the slideshow
    redundently stated I know

    Dah!!!
    Thanks so much,
    I was unaware of that feature, it works.

  • Putting a JLabel on top of a Player

    Lets say you have a JApplet. You now create a JPanel or JLayered pane and you add a player component on top of the whole panel (or pane) and you set it on the
    content pane. How would you put a JLabel on top of that player componenent? I have tried everything and nothing seems to work....
    Any suggestions would be appreciated...
    Melissa

    See http://java.sun.com/products/java-media/jmf/2.1.1/solutions/SwingJMF.html for information on using lightweight components (Swing) with JMF.
    -- Kevin

  • I have bought a new iPad 2 charger and it works absolutely fine but then I wanted to upload some pictures on the computer so I put the wire in the right places but it doesn't work so I tried my iPhone and it worked fine?

    I have bought a new iPad 2 charger and it works absolutely fine but then I wanted to upload some pictures on the computer so I put the wire in the right places but it doesn't work so I tried my iPhone and it worked fine?

    Plz answer as soon as possible

  • Recovered files in the trash.  How do I put them back to their original place so that they do not keep being recovered very time I open my Mac?

    I keep getting the same recovered files in the trash.  How do I put them back to their original place so that they do not keep being recovered very time I open my Mac?

    The recovered files are temporary files used by Mac OS X applications. Usually temporary files are deleted by an application when it no longer needs them. If an application quits unexpectedly, the temporary files may not be deleted by the application. When you restart your computer, Mac OS X moves these temporary files to the Trash.
    You can retrieve useful files by dragging them out of the Trash. In most cases, however, the temporary files are not important and it is safe to empty your Trash. Check with the manufacturer of the application if you are not sure.

Maybe you are looking for

  • How to use Space as field Separator?

    I have a flat file with space (multiple spaces between different fields) as a delimiter. Whenever I try to upload the file it doesn't allow me to perform. In the external tab when i chose CSV file and do not give any value in the file separator, it j

  • Lumia 920 does not accept Live.fi -email addres

    Hi, I just received a new Lumia 920. I have created in internet an windows email with ending @live.fi. I am not able to add that email account as a Window live Id. Where is the problem?

  • IPod Drive Problems

    I have looked before asking, so I feel safe posting this brainteaser. I have had my IPod for over a year and a half without any problems up until a few weeks ago. I forgot my charger at home and used my friends Apple to fill my battery. The problem w

  • Uninstalling IPOD and Itunes software

    I had various updates to IPOD Updater. Lo I found three prior versions on my computer and could not uninstall the earlier versions. I finally manually deleted them using Explorer and reinstalled the latest updater. I was then able to fix my Ipod. How

  • Problem converting to mpeg4

    I'm having a problem converting my music videos to mpeg4...they are in MOV format so I am able to put them into itunes, and everytime I try to "convert selection to ipod" it converts it very fast but when I try playing the video it just shows a white