Icon Position in JButton

I have an application wherein I am adding imageicons to Jbuttons dynamically. By defualt the icon is shown after the button text. How do i set it in such a way that the Icon appears befire the jbutton text

The icons appear to the left of the text for me by default. This would be for the default left to right orientation.
If you want to change the alignment, then read the API. There is a method that allows you to determine the horizontal placement of the text with respect to the icon.

Similar Messages

  • Desktop icons position not kept

    Hi. I'm using 10.6.2 and sometimes (not all) when I start my machine, the desktop icons (which I have arranged by snap to grid) are not where they used to be the last time I was with the cmputer on but they all show up aligned on the right of the screen, next to the hard drive icons in columns. I did not yet find a patteen like "this only happens if I have the computer turned of more than X x or y hours". Sometimes I leave for a couple of days and the icons are good when I come back. Sometimes just a few hours with the computer turned off and the icons position is not kept. Other time is the other way around.
    Any ideas? Someone with the same issue?
    Thanks.

    I had this problem, too, and brought it up with a "Genius" this morning. His solution -- which seems to have worked -- was first to show hidden files (using a utility or Terminal, as described elsewhere) and then delete the .DS_Store file which now appears on the desktop. The file rebuilt itself, and the icons now stay where I put them after a restart or relaunch of the Finder. You should rehide the hidden files once you've done this.
    I had previously tried resetting the PRAM and deleting a couple of plist files from the Preferences Library, which other people had recommended, but those solutions didn't work. This did. Thanks, Geniuses in Emeryville.
    Rick

  • Icon view, icon position not kept

    Most of my files are displayed in icon view. I have group them in positions easy to remember.
    Since upgrading to SL every now and then a folder (or two) will have the icons ordered by name and positioned in a grid even if I haven't give that command.
    Since this is annoying is there a solution to avoid that finder behavior?

    ok, that may be the reason for not keeping the icon positions but who except the finder will be responsible for a corrupt .DS_store file?
    There are other Finder problems not only on my MacBook Pro but also on the MacBooks running in our household since we upgraded to SL. These problems usually result in a spinning ball of death and one has to press the ON switch to restart the Mac.
    I haven't seen such issues in all previous upgrades from Mac OS X onwards. This is really disappointing since the SL upgrade was announced as a minor one but now it turns out as a nightmare to me.

  • Icon behavior in Jbuttons

    Hi,
    I'm a new programmer in java and I need help.
    I have to do one JButton matrix and I have to set one Icon to each JButton.The problem is that, I don't know how I can do to set more Icons to the same JButton and changing the Icon by click. I have to set 4 .gif Icon so after the 4th click i have to see again the 1st Icon. Hoping is clearly.
    Thanks.
    Code:
    package newpackage;
    import java.awt.*;
    import javax.swing.*;
    import java.io.*;
    * @author Student
    public class myform extends javax.swing.JFrame {
    JButton[][] buttons = new JButton[5][5];
    Integer[][] i = new Integer[5][5];
    Integer[][] j = new Integer[5][5];
    ImageIcon icon = new ImageIcon("c:/0.gif");
    String name=new String();
    ImageIcon icon1 = new ImageIcon
    ("C:/1.gif");
    ImageIcon icon2 = new ImageIcon
    ("C:/2.gif");
    ImageIcon icon3 = new ImageIcon
    ("C:/3.gif");
    /** Creates new form NewJFrame */
    public myform() {
    initComponents();
    setTitle("Button");
    setBounds(8,8,0,0);
    for (int i=1;i<buttons.length;i++){
    for (int j=1;j<buttons.length;j++){
    buttons[j] = new JButton(new ImageIcon ("c:/0.gif"));
    this.getContentPane().add(buttons[j]);
    this.pack();
    buttons[j].addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    JButtonActionPerformed(evt);
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
    private void initComponents() {
    getContentPane().setLayout(new java.awt.GridLayout(5, 6));
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    pack();
    // </editor-fold>
    * @param args the command line arguments
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new myform().setVisible(true);
    private void JButtonActionPerformed(java.awt.event.ActionEvent evt) {
    JButton who = (JButton) evt.getSource();
    if (who.equals(who)){
    who.setIcon(icon1);
    //return a;
    // Variables declaration - do not modify
    // End of variables declaration
    }

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    public class IconSwap implements ActionListener {
        BufferedImage[] images;
        int imageIndex = 0;
        public IconSwap(BufferedImage[] images) {
            this.images = images;
        public void actionPerformed(ActionEvent e) {
            JButton button = (JButton)e.getSource();
            ImageIcon icon = new ImageIcon(images[++imageIndex % images.length]);
            button.setIcon(icon);
        private JPanel getContent() {
            JButton button = new JButton(new ImageIcon(images[0]));
            button.addActionListener(this);
            JPanel panel = new JPanel(new GridBagLayout());
            panel.add(button, new GridBagConstraints());
            return panel;
        public static void main(String[] args) throws IOException {
            String[] ids = {
                "-----", "-c---", "-cg--", "-c-h-"
            BufferedImage[] images = new BufferedImage[ids.length];
            for(int j = 0; j < images.length; j++)
                images[j] = ImageIO.read(new File("images/geek" + ids[j] + ".gif"));
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(new IconSwap(images).getContent());
            f.setSize(300,300);
            f.setLocation(200,200);
            f.setVisible(true);
    }

  • Snow Leopard Finder Icons Position

    Hi!
    Sometimes, when i restart the OS the system arrange the icons positions on the left side of the screen...
    I have a lot of icons (using two monitors) and this thing is very, very unpleasant!
    Anyone solved this problem?
    The genius tech's don't have a clue...
    Regards

    Hi!
    The problem isn't in the menu/option, it seems that when you connect external discs (USB or Firewire) and restart the machine, the icons on the desktop are rearranged by the system itself losing the initial position used by the owner of the account.
    If tried some tips found in the web but didn't solve the problem.
    Regards

  • I'd like to install itunes on new laptop but I don't want to lose actual icon position on my iphone

    I'd like to install itunes on a new laptop. Last year I did this operation and when I syncronized my iphone I lost the icon position and custom app folder. I didn't lose the personal data. How can I do?

    Copy everything from your old computer, or your backup copy of your old computer, to the new one.

  • Detect topleft icon position of the JInternalFrame window

    Hi,
    How to get the topleft icon position of an internal window ? because I want to active the system menu of the internal frame by click mouse . Thanks.
    Liwei

    Can you use getLocation(...) of the JInternalFrame and then 'guess' that the icon will be (+20, +20) from the location of the internal frame? Here is a thread that does this for a JFrame:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=238132

  • Why are desktop icon positions for some files forgotten on restart

    On restart/reboot some of the file icon positions are forgotten and the files reappear stacked over the startup drive icon.  The remainder of the files on the desktop are in their correct/previous positions.  Why are somefile locations not remembered?

    Sounds like the .DS_Store invisible file is corrupt.  That is my wild guess.  There is a .DS_Store invisible file for each folder that the Finder visits.  It is where the Finder stores this position information.
    NOTE:  The following suggestions will cause the Finder to forget the positions of everything in the target folder, but after that the Finder should be able to remember going forward.  If you have some icons in the correct positions and you do not want to forget where they were, you should take a screen shot, or create a map (with pencil and paper), or other way to memorize where they were.
    There are utilities that can toggle the Finder internal settings to display invisible files, and then reset the settings so they are again hidden (you would trash the .DS_Store of the misbehaving folder while it was visible, then reloaunch the Finder or reboot, but a Finder relaunch is faster).
    There are Terminal commands that can be used to just remove the .DS_Store file.
    The killall Finder is needed to relaunch the Finder.  You could also use Apple menu icon -> Force Quit... -> Finder -> Relaunch.
    If a folder does not have a .DS_Store when the Finder opens the folder, the Finder will create a new one and assigns all the icons a default position.  Then you should be able to reposition the icons as you desire, and it should remember them from that point forward.

  • How do I preserve my preferences, interface personalisations (icon positions, and so) ???

    How do I preserve my preferences, interface personalisations (icon positions, and so) ?, so that when I reinstall my Windows XP Pro and Windows 7, I just had to copy or apply the correspondent(s) file(s), without having to reconfigure all newly.
    I've posted this in the reader forum, but I get no answer, as I need assistance for reader, acrobat, and photoshop, It comes to me, that may be it was posted in the wrong place. Hope get some reply this time, as I need to reinstall my OS.
    Thanks in advance.

    Ooh, thank you Test for the quick reply
    If you want a definite answer (but don't be at all hopeful), you need to contact Adobe.
    That's the problem, I can't get any answer from them, for this I count on the ingenious ideas users may have...
    It isn't very likely to be in files these days, but buried somewhere deep in the registry.
    I was thinking something like that, because I've done a deep search in the file explorer, with no success.
    As I'm a little clumsy, have you any idea, how and where I may find the so wanted information ?
    Thank you again.

  • Interchange positions of jbutton inside jpanel

    Hi Friends,
    I'm trying interchange the position of JButtons inside a JPanel and between the Jpanels.
    I'm unable to find the exact releasing positions.
    can anyone help me telling the exact procedure .
    here is the code
    Container con = jb.getParent();     
         con.remove(jb);
    insertPosition2 = con.getComponentZOrder((Container)jb);
    if(con.getComponentCount() == insertPosition2)
                             con.add(jb);
                        else
                             con.add(jb,insertPosition2);
    thanx,
    Sunil.

    I've never tried this myself, but the documentation for Container#getComponentZOrder says:
    The higher a component is in the z-order hierarchy, the lower its index.
    Maybe you could try withinsertPosition2 = con.getComponentZOrder((Container)jb);In any case, the correct approach to this kind of troubleshooting is to insert System.out.println statements in between the lines posted so you can observe whether your assumptions about the values the methods return are correct ones.
    Use code tags to post codes -- [code]CODE[/code] will display asCODEOr click the CODE button and paste your code between the {code} tags that appear.
    If you require further help, please post a SSCCE
    db

  • Adding an Icon to a JButton Component - Not working

    Hi all,
    Please help me by saying, why the below gevon SSCE doesnt work.
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import javax.swing.AbstractAction;
    import javax.swing.AbstractButton;
    import javax.swing.Action;
    import javax.swing.BorderFactory;
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.UIManager;
    public class CreateWindow {
        public CreateWindow(String module, String id){
             if(module.equals("mail")){
                  JPanel mail = new JPanel(null);
                  mail.setPreferredSize(new Dimension(500, 350));
                  //Color colr = new Color(222, 236, 255);
                  mail.setBackground(Color.WHITE);
                  JLabel file = new JLabel("File Name:");
                  file.setBounds(18,25,75,50);
                  // Retrieve the icon
                 Icon icon = new ImageIcon("ei0021-48.gif");
                 // Create an action with an icon
                 Action action = new AbstractAction("Button Label", icon) {
                     // This method is called when the button is pressed
                     public void actionPerformed(ActionEvent evt) {
                         // Perform action
                 // Create the button; the icon will appear to the left of the label
                 JButton button = new JButton(action);
                  mail.add(button);
                  buildGUI(mail,500, 350);
        public void buildGUI(JPanel panel, int width, int height)
            JFrame.setDefaultLookAndFeelDecorated(true);
            UIManager.put("activeCaption", new javax.swing.plaf.ColorUIResource(Color.LIGHT_GRAY));
            JFrame f = new JFrame("Propri�t�s:");
            f.setIconImage(new ImageIcon("save.gif").getImage());//need an image file with black background
            changeButtonColor(f.getComponents());
            f.getContentPane().setBackground(Color.WHITE);
            f.getContentPane().add(panel);
            f.getRootPane().setBorder(BorderFactory.createLineBorder(Color.PINK,2));
            f.setSize(width,height);
            f.setLocationRelativeTo(null);
            f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            f.setVisible(true);
          public void changeButtonColor(Component[] comps)
            for(int x = 0, y = comps.length; x < y; x++)
              if(comps[x] instanceof AbstractButton)
                ((AbstractButton)comps[x]).setBackground(Color.LIGHT_GRAY);
                ((AbstractButton)comps[x]).setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
              else if (comps[x] instanceof Container)
                changeButtonColor(((Container)comps[x]).getComponents());
    }I call the above given class constructor as given
    public class Test {
         public static void main(String args[]){
              CreateWindow cw = new CreateWindow("mail","Test.doc");
    }Rony

    RonyFederer wrote:
    I have the images and class files inside
    F:\Testing3\Application\src\booodrive
    Do you have the class files or java files here?
    You should put the gif where the .class files are located, and use getResource as Encephalopathic wrote, or:
    Icon icon = new ImageIcon(ClassLoader.getSystemResource("ei0021-48.gif"));
    When I did as you said using System.out.println(new File("ei0021-48.gif").getAbsolutePath());, I got the following output.
    F:\Testing3\Application\ei0021-48.gif
    That's the current running directory.

  • How can I change a user icon position?

    How can I change the position that Yosemite determines for where a user icon is positioned on the login screen? I'm the admin and I added a standard user and the icon placement for that user is first, I'm second, and Guest User is third...it does not appear to be alphabetical. I'd like to switch the first two so my user icon is the first one on the left.

    Locate a folder icon you wish to use. Select it and press COMMAND-C to copy. Select the folder you want changed. Press COMMAND-I to open the Get Info window. At the top left you will see that folder's icon. Click on it then press COMMAND-V to paste.
    If you want to create your own icons then you will need an application to do that. For example, Folder Icon Changer 3.0.7.
    Google searches will locste tons of pre-made folder icons you csn use. Some are free and some are not.

  • How to find icon position of currently executed VI on caller's block diagram

    Dear forum,
    I currently try to use a LabVIEV VI as a simple sequencer: Several (very slow) actions have to execute one after another. Each action is represented by a Sub-VI, some actions are executed several times. My task is to visualize the currently executed Sub-VI somehow.
    My first intention (simply manipulate the icon of the currently running VI with "VI Icon.Get as Image Data" / "VI Icon.Set from Image Data" invoke nodes) failed, because this changes the icon of ALL instances of this VI; if you use the same VI several times, the icons of all these VI are changed (see here: http://forums.ni.com/t5/LabVIEW/How-to-change-animate-icon-of-currently-running-VI/m-p/3120754/highl...
    My current approach is to use an image of the block diagram (with "VI: Block Diagram: Get Image Scaled" invoke method) within a picture control of the front panel and to work within this control. But for this I need to know the position of the icon of the currently executed VI. I know that I can evaluate Bounds and Position via the GObj properties, but how do I find the currently running VI (note that a VI may reside several times on the block diagram, so the name of the VI is not unique)? IMHO the simpliest way would be if a VI could find its icon on the caller's block diagram itself when executed...
    It's clear that this position is not the position on the picture yet, but this conversion is a small piece of work...
    Regards,
    cpschnuffel
    Solved!
    Go to Solution.

    Yamaeda wrote:
    Run it in highlight mode, done.
    Sure if you don't mind having functional checks taking hours instead of minutes...okay maybe that is exagerating for a simple VI like this, but it would increase cycle time.  Honestly I think the best solution would be to use the helper VI that was mentiond before, which keeps track of what VI is running.  You can of course use scripting to get the block diagram image, but there isn't a good way to know what exact VI is running using VI server.  Here are a few discussions.
    https://lavag.org/topic/16660-how-to-get-actual-vi-execution-state/
    https://decibel.ni.com/content/thread/18687
    Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
    If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.

  • Sticky notes icon position

    Is there any way to position sticky notes icon more accurately on the page?
    Default anchor point of the note is the center of an icon, not the tip of the arrow below or some corner. Consequently, the icon covers some of the text or small graphics and at low zoom level you can't see exactly which text the note is concerning.
    We lose a lot of time zooming in and out on pages with large amount of relatively small text, icons or pictograms and with many comments on it, sent from our customer. Because they have smaller monitors, they see the position of the note a bit different than us and it takes time for us to figure out what they're actually commenting.
    This has been a pain in the back for us as far as I can remember.
    If there is nothing we can do, let this post be a sort of a feature request. ;)
    Thanks,
    Tomaz

    Thanks. Of course I know the note can be moved.
    The problem is, if the icon is on top of a block of small text, the icon can cover 3 or 5 lines of text and you have too zoom in to see which line it belongs to. I can't move it before I see where it belongs.
    It becomes annoying if you have 20+ notes on a page and 60 pages of text.
    I hope I've explained my problem understandably.

  • Icon position syntax

    Hello,
    I try to implement an experiment in which a same picture has
    to be repeated randomly at different (predefined) positions on the
    same display, and that during the whole experiment... Has somebody
    an idea to help my dealing with this problem?

    "Alain Chav" <[email protected]> wrote in
    message
    news:g11bdf$7k1$[email protected]..
    > Hello,
    >
    > I try to implement an experiment in which a same picture
    has to be
    > repeated
    > randomly at different (predefined) positions on the same
    display, and that
    > during the whole experiment... Has somebody an idea to
    help my dealing
    > with
    > this problem?
    >
    One way you can do it is to use dibapi. Look at the Screencp
    showme for more
    details on that. Another way you can do it is simply have as
    many icons as
    predefined positions, or one icon with images that are
    dynamically linked
    with variables to the image. Turn the copies of the image on
    and off by
    changing the variables.
    If you only need to move ONE copy of the image to the
    predefined position,
    you can either use a motion icon or use variables in its
    position x and
    position y fields and erase it, reset the variables, and
    redisplay it.
    HTH;
    Amy

Maybe you are looking for