Setting JLabels to be on top.

I'm making a Deck Card that shuttle and sorts the card. I was able to display the images using a JLabel with ImageIcon. I can get to display the images and everything, but my only problem is when i'm display the image that the first image is on top of the second and the second is on top of the third.
I want it to display the opposite order so I want the first one to be under the second and the second to be under the third.
Is there a way that I can get the a label to be on top of the other?
I forgot to mentioned that they have different X and Y Coordinates.

Actually in any panel etc you have a layout which layouts the componsnts in his own way. So you need a layout that displays components as they are.
Try running following code:
import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.LineBorder;
public class LayoutPanel extends JPanel {
   public LayoutPanel() {
      setLayout( new EmptyLayout( new Dimension( 400, 300 ) ) );
      JLabel[] labels = new JLabel[10];
      for( int i = 0; i < 10; i++ ) {
         labels[i] = new JLabel( "Label " + i );
         labels.setVerticalAlignment( JLabel.TOP ); // show text at top position
labels[i].setLocation( 13 * i, 13 * i ); // set location
labels[i].setSize( new Dimension( 100, 100 ) ); // set size
int colour = i + 10;
labels[i].setBackground( new Color( 9 * colour, 10 * colour, 11 * colour ) );
labels[i].setBorder( new LineBorder( Color.black, 1, true ) ); // set border
labels[i].setOpaque( true ); // set to draw its all pixels
add( labels[i], 0 ); // set at top means last on top, otherwise use add(labels[i]) to set first on top
public static void main( String argv[] ) {
JFrame frame = new JFrame( "Polygon Demo" );
LayoutPanel layout = new LayoutPanel();
frame.setContentPane( new JScrollPane( layout ) );
frame.pack();
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setVisible( true );
class EmptyLayout implements LayoutManager {
private Dimension size = null;
EmptyLayout( Dimension size ) {
this.size = size;
public void addLayoutComponent( String name, Component comp ) {}
public void removeLayoutComponent( Component comp ) {}
public Dimension preferredLayoutSize( Container parent ) {
return size;
public Dimension minimumLayoutSize( Container parent ) {
return size;
public void layoutContainer( Container parent ) {}
Regards,
Humayun

Similar Messages

  • Setting an icon on the top right zone of screen

    Nice day.. I got a question:
    I need to set an Icon which has to be set all time to the top
    right corner of the screen, no matter what size is the screen...
    how do I achieve it ? I will appreciate your help,

    On 31 Jul 2008 in macromedia.dreamweaver, Sw Jiten wrote:
    > Dear Murray :
    >
    > 1) I can not enter the link you sent me.. I do not know
    why... I
    > even tried :
    > www.murraytestsite.com and nothing...
    Works fine here.
    > 2) You said you neither approve parts of my code... I
    will
    > appreciate to know
    > what parts...? This ia s great opportunity for me to
    learn from a
    > big one like you, so please do not dissapoint me and
    show me how to
    > optimize some parts that you might consider... thanks
    .style15 {font-size: 10px}
    </style>
    <!--Fireworks 8 Dreamweaver 8 target. Created Sat Apr 12
    00:55:50 GMT-0500 2008-->
    </head>
    <body bgcolor="#74acc7">
    <table width="779" border="0" align="center"
    cellpadding="0" cellspacing="0">
    <!-- fwtable fwsrc="websitetemplate.png"
    fwbase="websitetemplate.gif" fwstyle="Dreamweaver" fwdocid =
    "1112975483" fwnested="0" -->
    <tr>
    <td><img src="img/spacer.gif" width="20" height="1"
    border="0" alt="" /></td>
    <td><img src="img/spacer.gif" width="9" height="1"
    border="0" alt="" /></td>
    <snip>
    <div id="flashheader">
    </div>
    <script type="text/javascript">
    var so = new SWFObject("header.swf", "movie", "557", "87",
    "8", "#74ACC7");
    so.write("flashheader");
    </script>
    <snip>
    <td rowspan="5" colspan="7">
    Murray's being way too nice. Where to begin?
    See the style above? Note that it says 'style15' - it means
    that
    you're using DW's properties bar to create a whole bunch of
    separate
    little CSS styles. They're tough to keep track of, and you
    wind up
    with a bunch of them scattered through your code. Think
    through your
    CSS, create your classes in your (external) stylesheet, and
    apply them
    as necessary.
    You used Fireworks to export HTML code. Fireworks creates
    notoriously
    fragile HTML. That's the reason for the line of spacer .gifs.
    They're totally unnecessary and bloat your code with no need.
    That's
    also the reason for having a rowspan and a colspan on the td.
    I
    wouldn't even attempt to try to sort something like that out.
    You used Flash for navigation. That doesn't work for people
    using
    assistive devices to visit your site, it doesn't work for
    people who
    don't have Flash, and probably more important, it doesn't
    work for
    search engines.
    You use an iframe on the page. That creates an internal
    scrollbar.
    This one is arguable, but many of us consider internal
    scrollbars to
    be a detriment to usability.
    In my opinion - your best bet? Start over. Take your
    fireworks comp,
    slice it up, and use the slices as parts to a page you create
    using
    one of DW's built-in sample pages.
    Joe Makowiec
    http://makowiec.net/
    Email:
    http://makowiec.net/contact.php

  • Setting JLabel's default size

    Hi:
    I've had a problem of setting JLabel's size. I used several methods such as setMaximumSize() and setMinimumSize() to set the size of JLabel so that it will have a defined size, no matter how much text it contains. But it doesn't work.
    The JLabel is added in a JPanel. I've also tried to use those setSize() methods on JPanel, it doesn't work either.
    Please help!
    thanks!

    Which layout manager are you using? Not all layout managers use maximum size and minimum size -- for example GridLayout will size your labels to fit exactly in the grid regardless.

  • I Have a Mac 10.2 and a HP 6700 all-in-one printer,when I set-up to print the top line of the image is cut off

    I Have a Mac 10.2 and a HP 6700 all-in-one printer,when I set-up to print the top line of the image is cut off

    If there isn't a Page Setup in the Print Dialog, open Text Edit>Edit>Page Setup, check borders there or use Custom Page setup & save.

  • How to set a date variable to "top of the next hour"?

    hi
    i have a idler script that i want to continually run. at the moment it idles for an hour, then runs the "on idle" handler.
    what i would prefer is to set this to the "top of the next hour", for any hour. e.g. if its 4:35, it would set it to 5:00. is there a simple, standard way of doing this, or will i need to do some maths to get to the result?
    regards
    jingo_man

    Hello
    Using idle handler, you'd need to calculate the seconds to the next hour.
    Something like the below.
    Cheers,
    H
    --CODE
    on idle
    -- code for idle handler here
    set t to (current date)'s time -- current time
    set d to (t div 3600 + 1) * 3600 - t -- seconds to the next hour
    return d -- wait until then
    end idle
    --END OF CODE

  • JTable - programmatically setting the left column and top row

    I have a JTable in a JScrollPane. I would like to be able to programmatically scroll the table so that a certain column is shown as the left most column in the table, and/or a certain row is shown as the first visible row in the table.
    This is to allow a user to enter a value for the column or row that the want to be on the left or top of the viewport (ie, it is up to the user how they want to move the initially see the table).
    Any help would be much appreciated,
    Cheers, Sean

    Here is one way to do it:
    1) use the getCellRect(row,column,false) to get a rectangle for the cell you wish to display in the upper left corner
    2) use the getVisibleRect() method to get the viewport
    3) set the viewport x and y coordinate to be the same as the cell x,y coordinate
    4) use the scrollRectToVisible method to scroll to the desired area
    For example:
    Rectangle cellRect=myTable.getCellRect(5,10,false);
    Rectangle vis=myTable.getVisibleRect();
    vis.x=cellRect.x;
    vis.y=cellRect.y;
    myTable.scrollRectToVisible(vis);
    Caveat: posted code has not been tested!
    ;o)
    V.V.

  • How to set a menu as a top or root one

    Hello to all,
    I am using Encore CS5.1
    1)The problem.
    I would like to set the first menu in the sequence as the "Root menu" (or "Top menu" depending on the remote control).
    Unfortunately in the DVD I have made each time I click on the key "Top menu" the DVD comes back to a submenu.
    2)The details
    Let's look at the following flowchart.
    I would like to transform the menu "Nicole_et_JP" (yellow circle) as the "Top menu". The problem is that when I click on the "Top menu" key on my remote control the DVD player goes to "C_etait_nous_menu" (red circle).
    Maybe the numbers B2 (for the first one) and B1 (for the second one) are related to the problem.
    3)The question
    I have not found out the answer in the help. So could you help me to learn how to set a given menu as a root (or top) one.
    Any help appreciated, thank you.
    Jean-Paul

    I don't know where I got this note, but it illustrates why I stay confused about remotes:
    DVDs have a title or top menu, which will take the user to the menu specified for title remote. Timelines have a menu property, which takes you to the menu specified for the timeline (menu remote). The two should not be confused.
    Go to the Flowchart and select the Disc icon. Then look at the Properties panel. Set the title remote as you wish - where will the user go when they push the top menu button.
    So, logically, I suspect that you do not have the "title remote" set correctly.
    But it may also turn out that the buttons are not doing what the Adobe help file says. (I suspect that is where I got the above verbiage. But I can't find it now.) And I have not gotten around to testing this. It is one of those things that can only be tested using real remotes and not computer player.
    Maybe the numbers B2 (for the first one) and B1 (for the second one) are related to the problem.
    The B1 and B2 show the default button for the menu.

  • How to set module to be on top of another module

    hello guys!! i'm just newbie in flex, and cant figured out
    how to manage loaded modules to set who's on top of each other. if
    i load one module then loads another one, the last module loaded is
    the one on top what i want to happen is when i click on the first
    module it should be brought on top. how can i do these?

    here is my code inside a function that loads the module, this
    is being called from a menuBar event
    var moduleLdr:ModuleLoader = new ModuleLoader();
    moduleLdr.id = event.item.@label;
    moduleLdr.url = event.item.@data;
    this.addChild(moduleLdr);

  • How can i set the item properties at top level

    Dear all
    i want to set the responsiblityname and operating unit name at the top of the page
    is there any specific regions are there to set at the top level of the page(Image region)
    Regards
    Sreekanth

    FND Framework Compataibiity Mode is a Profile Option you can set the value as 11.5.10.
    And instead of creating product branding progrmatically create product branding and incontextbranding at design time.
    Also, for both of these items we have View Object and View Instance properties...
    For this you take two transient attributes in VO and then as you have grabbed the responsibility name and operating unit...
    then you can set these values on these Transient attributes and then they will be visible on Top region of page.
    Associate these transient Attributes on product branding and incontextbranding items.
    Thanks,
    Gaurav

  • Set Opacity of JPanel on top of Image Background

    Good day.
    By referring to the Post
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=506054
    I successfully set the jpg as my application background.
    I facing a problem to set opaque of the Container or the Panel.
    Anyone of Swing expert may help?
    My code :
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.awt.image.*;
    import javax.swing.border.*;
    import java.net.URL;
    import java.net.URI;
    import java.io.*;
    import javax.imageio.*;
    public class MainMenu{
         private String msgStepSelectAction;
         // Panel Background
         JPanel bgPanel;
         // Panel GUI
         private JPanel upPanel;
         private JPanel cenPanel;
         private JPanel botPanel;
         // Control GUI
         static JFrame f;
         static JLabel lblStepSelectAction ;
         static ButtonGroup btnGroup;
         static JRadioButton jrbtn1;
         static JRadioButton jrbtn2;
         static JButton btn3;
         // default constructor
         public MainMenu(){
              //this is method to constructor GUI components
              GUISetting();
         public void GUISetting(){
              // This is background design
                final JPanel cp = new JPanel(new BorderLayout());
            final JFrame f = new JFrame("System ");
            File img= new File("c://bg_new2.jpg");
              URI uri = img.toURI();
                try {
                          final Border bkgrnd = new CentredBackgroundBorder(ImageIO.read(uri.toURL()));
                      Runnable r = new Runnable() {
                          public void run() {
                              cp.setBorder(bkgrnd);
                              cp.repaint();
                      SwingUtilities.invokeLater(r);
                catch(Exception e){
              // Construct the container location
              f.getContentPane().add(cp);
              Container c = f.getContentPane();
             c.setLayout(new BorderLayout(10, 10));
              upPanel = new JPanel();
              cenPanel = new JPanel();
              botPanel = new JPanel();
              upPanel.setOpaque(false);
              cenPanel.setOpaque(false);
              botPanel.setOpaque(false);
              //set the location of the panel
             c.add(upPanel,BorderLayout.PAGE_START);
             c.add(cenPanel,BorderLayout.CENTER);
             c.add(botPanel,BorderLayout.SOUTH);
              msgStepSelectAction="Please Select the Action that you want";
              // Label
              lblStepSelectAction = new JLabel(msgStepSelectAction);
              // Button
              btnGroup = new ButtonGroup();
              jrbtn1= new JRadioButton("1");
              jrbtn2 = new JRadioButton("2");
              btnGroup.add(jrbtn1);
              btnGroup.add(jrbtn2);
              btn3 = new JButton("Proceed");
              // here is control button
              upPanel.add(lblStepSelectAction);
              cenPanel.add(jrbtn1);
              cenPanel.add(jrbtn2);
              botPanel.add(btn3);
              jrbtn1.setOpaque(false);
              btnProceed.addActionListener (new ActionListener(){
                   public void actionPerformed(ActionEvent ae){
                        if (jrbtnStego.isSelected()==true){
                             StegoControl stegoControl = new StegoControl();
                             StepSelectStegoMethod stepSelectStegoMethod = new StepSelectStegoMethod(stegoControl);
                             f.dispose();
                        else if (jrbtnDeStego.isSelected()==true){     
                             DeStegoControl deStegoControl = new DeStegoControl();     
                             StepSelectDeStegoMethod stepSelectDeStegoMethod= new StepSelectDeStegoMethod(deStegoControl);
                             f.dispose();          
                        else{
                             JOptionPane.showMessageDialog(null,"Please select a function to proceed","",JOptionPane.ERROR_MESSAGE);
              // set the properties of the system
              f.setContentPane(cp);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setSize(810,630);
            f.setLocationRelativeTo(null);
            f.setVisible(true);
         public static void main(String [] args)throws Exception{
              MainMenu object = new MainMenu();
    class CentredBackgroundBorder implements Border {
        private final BufferedImage image;
        public CentredBackgroundBorder(BufferedImage image) {
            this.image = image;
        public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
            int x0 = x + (width-image.getWidth())/2;
            int y0 = y + (height-image.getHeight())/2;
            g. drawImage(image, x0, y0, null);
        public Insets getBorderInsets(Component c) {
            return new Insets(0,0,0,0);
        public boolean isBorderOpaque() {
            return true;
    }Thank you ...

    f.setContentPane(cp);Use better variable names an maybe you wont make mistakes like this.
    You create a "content pane" (cp) panel but you never add any components to it.
    So get rid of the code where you create the "c" variable as it is not required.
    // c.add(upPanel,BorderLayout.PAGE_START);
    // c.add(cenPanel,BorderLayout.CENTER);
    // c.add(botPanel,BorderLayout.SOUTH);
    cp.add(upPanel,BorderLayout.PAGE_START);
    cp.add(cenPanel,BorderLayout.CENTER);
    cp.add(botPanel,BorderLayout.SOUTH);

  • TS2621 I have an e-mail set up on mt desk top and I-pad. Recently I had to change the password on my desktop. The next time I tried to open my I-pad e-mail it said I had the wrong user name or password. I changed the password to match the one on my dt, sa

    I keep getting error message on my I-Pad e-mail, user name or password incorrect. I reset the password with a new one and it says same thing. I have same e-mail on desktop. Same password. Any ideas?

    If you can't send mail, but can receive it  - Check the outgoing mail server setting. Make sure that your username and password are in there.
    Settings>Mail, Contacts, Calendars>Your email account>Account>Outgoing mail server - tap the server name next to SMTP and check in the primary server and make sure your username and password are entered and correct - even if it says that the password is optional.

  • SETTING C8180 PRINTER FOR DESK TOP (WIRED) AND ALSO NOTEBOOK WIRELESS

    I have a C8180 already hooked to my desk top that works fine.  I brought a Notebook HP dv7-3173nr  that runs Windows 7 and I want to add it so that I can also print to the same printer wireless. Bottom line I will have two PC's printing to the same printer, one via the USB cable and one wireless.  I am pretty new at these things so if possible make it easy for me to understand,, PLEASE.  I am using a NETSYS e2000 router
    Ben
    This question was solved.
    View Solution.

    Assuming both of your computers are connected to your router, your best option is to connect the printer to the router for all to use.  If you do what you are suggesting, you will only be able to share the print function with your new notebook PC and it is hard to do.
    Read starting on page 33 of the manual as to how to connect your printer to your router.  Basically, you will connect it to your router via the front of the printer (Wireless Setup Wizard), then load the software on your PC's (from here) following instructions for a "Through the Network" installation.
    Say thanks by clicking "Kudos" "thumbs up" in the post that helped you.
    I am employed by HP

  • Setting theme as either desk top page or screen saver

    similiar ? I asked before .... how can I see "more" of a theme ... much like when one sets a theme in Chrome .... its the whole page ..... thats what I want on Firefox.

    See also:
    * https://support.mozilla.org/kb/Using+themes+with+Firefox
    * http://kb.mozillazine.org/Themes (Lightweight theme)
    A Light weight theme (Persona) covers the user interface part of Firefox (toolbar area) and not the browser window with the web pages.
    Add extra empty toolbars if you want to see more of that theme.<br />
    You can create extra toolbars to get extra space via View > Toolbars > Customize<br />
    You have to put something on a toolbar (drag a Space item onto it) before closing the Customize window because empty toolbars are automatically removed.

  • Within a certain app, how do I set up tabs at the top of my iPad?

    I have a app that we use within our Church. I want to have multiple publications opened at the same time and be able to tab from one to the other. Is this possible?

    If you told us the name of the app someone here might be familiar enough with that specific app to answer your question. Or you could contact the apps developer to find out if the feature you describe is available.

  • When using email via iCloud, when I try to reply to emails, the cursor defaults to the bottom of the chain. How can it be set to default to the top?

    PDF reader will not open certain documents. I have to download to desktop and open PDF documents there. No similar problem if using Safari. Already loaded PDF plugin for Firefox. Any guesses?

    Also, This is the message I receive when the page doesn't open:
    The connection was reset
    The connection to the server was reset while the page was loading.
    The site could be temporarily unavailable or too busy. Try again in a few moments.
    If you are unable to load any pages, check your computer's network connection.
    If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web.

Maybe you are looking for

  • Possible Imminent Hard Drive Failure?

    First off I have an Early 2011 MacBook Pro running OSX Mountain Lion.  Avast version 7.0 is running as my anti-virus software with current definitions.  I'm a network administration student so I run 2 or 3 virtual machines simultaneously to replicate

  • [Solved] Postfixadmin, can't run setup.php

    First time for me to try setting up any server stuff with arch, so forgive if I come across as clueless The story is I followed this page from the arch wiki:  https://wiki.archlinux.org/index.php/SO … #SMTP-AUTH to setup postfix, dovecot and postfixa

  • My trouble is ActiveX Control for Flash Player could not be registered

    I follow all the instructions on your pages about this trouble and I'm still have troubles. OS= windows 7 64 bits IE8, the one I was using and I have the trouble was the 32 bits version. also I have read a couple of post about this and I checked at t

  • Portfolio Recovery

    I have this collection account still on my credit after being paid in full. I was told they would remove it and I have wrote them yet again another GW letter. My question is the DOFD is 12/2009. Should this really still be reporting on my credit? Wha

  • PAPI Service Interfaces not exposed as Web Services

    Hi,   In guide Javadoc_PAPI_SAPME_150 there are some public interfaces that are not present as Web Services in SAP NetWeaver Application Server -> Single Service Administration: Service Definitions.   The list of missing interfaces is: ArchiveService