Buttons become the same size as my iamge??? PLEASE HELP!!

Hi guys,
I I'm trying to setup a JFrame where i have an image above some buttons. They don't necessarily have to be in the same column but for soe reason, when i add the picture and the buttons go vertically down from the image, the become the same size as the image? The following code describes my contentPane. Please help!
public Component createComponents() {
JButton button = new JButton("I'm a Swing button!");
button.setMnemonic(KeyEvent.VK_I);
button.addActionListener(this);
label.setLabelFor(button);
JButton button1 = new JButton("I'm a Swing button!");
     button1.setMnemonic(KeyEvent.VK_I);
     button1.addActionListener(this);
label.setLabelFor(button1);
JButton button2 = new JButton("I'm a Swing button!");
     button2.setMnemonic(KeyEvent.VK_I);
     button2.addActionListener(this);
label.setLabelFor(button2);
JButton button3 = new JButton("I'm a Swing button!");
     button3.setMnemonic(KeyEvent.VK_I);
     button3.addActionListener(this);
label.setLabelFor(button3);
JButton button4 = new JButton("I'm a Swing button!");
     button4.setMnemonic(KeyEvent.VK_I);
     button4.addActionListener(this);
label.setLabelFor(button4);
JLabel label = new JLabel();
     URL loc = getClass().getResource("smalllogo2.gif");
     Icon icon = new ImageIcon(loc);
     label.setSize(icon.getIconWidth(), icon.getIconHeight());
label.setIcon(icon);
JLabel label2 = new JLabel();
     URL loc2 = getClass().getResource("SheeraAutoRepair2.jpg");
     Icon icon2 = new ImageIcon(loc2);
     label2.setSize(icon.getIconWidth(), icon.getIconHeight());
label2.setIcon(icon2);
* An easy way to put space between a top-level container
* and its contents is to put the contents in a JPanel
* that has an "empty" border.
JPanel pane = new JPanel(new GridLayout(0, 1));
pane.setLayout(new FlowLayout(FlowLayout.RIGHT));
pane.add(label);
pane.add(button);
pane.add(button1);
pane.add(button2);
pane.add(button3);
pane.add(button4);
pane.setBorder(BorderFactory.createEmptyBorder(
30, //top
30, //left
10, //bottom
30) //right
pane.setBackground(Color.white);
return pane;
}

multi-post. Please answer in this posting:
http://forum.java.sun.com/thread.jspa?threadID=694396

Similar Messages

  • Buttons become the same size as my image?? PLEASE HELP

    Hi guys,
    this is the second posting of this topic, as in the first one i didn't post my code properly (sorry!!!)
    My problem is that the buttons i have in the code come up as the same size as the 'Goldsmiths' Image. How can i alter the provided code to make the image stay the same size and the buttons to have the default button size?
    Thanks
    //SSPanesar
    //copyright 2005 all rights reserved
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.URL;
    public class SwingApplication implements ActionListener {
    private static String labelPrefix = "Number of button clicks: ";
    private int numClicks = 0;
    final JLabel label = new JLabel(labelPrefix + "0 ");
    //Specify the look and feel to use. Valid values:
    //null (use the default), "Metal", "System", "Motif", "GTK+"
    final static String LOOKANDFEEL = "System";
    public Component createComponents() {
    JButton button = new JButton("I'm a Swing button!");
    button.setMnemonic(KeyEvent.VK_I);
    button.addActionListener(this);
    label.setLabelFor(button);
    JButton button1 = new JButton("I'm a Swing button!");
         button1.setMnemonic(KeyEvent.VK_I);
         button1.addActionListener(this);
    label.setLabelFor(button1);
    JButton button2 = new JButton("I'm a Swing button!");
         button2.setMnemonic(KeyEvent.VK_I);
         button2.addActionListener(this);
    label.setLabelFor(button2);
    JButton button3 = new JButton("I'm a Swing button!");
         button3.setMnemonic(KeyEvent.VK_I);
         button3.addActionListener(this);
    label.setLabelFor(button3);
    JButton button4 = new JButton("I'm a Swing button!");
         button4.setMnemonic(KeyEvent.VK_I);
         button4.addActionListener(this);
    label.setLabelFor(button4);
    JLabel label = new JLabel();
         URL loc = getClass().getResource("smalllogo2.gif");
         Icon icon = new ImageIcon(loc);
         label.setSize(icon.getIconWidth(), icon.getIconHeight());
    label.setIcon(icon);
    JLabel label2 = new JLabel();
         URL loc2 = getClass().getResource("SheeraAutoRepair2.jpg");
         Icon icon2 = new ImageIcon(loc2);
         label2.setSize(icon.getIconWidth(), icon.getIconHeight());
    label2.setIcon(icon2);
    * An easy way to put space between a top-level container
    * and its contents is to put the contents in a JPanel
    * that has an "empty" border.
    JPanel pane = new JPanel(new GridLayout(0, 1));
    //pane.setLayout(new FlowLayout(FlowLayout.RIGHT));
    pane.add(label);
    pane.add(button);
    pane.add(button1);
    pane.add(button2);
    pane.add(button3);
    pane.add(button4);
    pane.setBorder(BorderFactory.createEmptyBorder(
    30, //top
    30, //left
    10, //bottom
    30) //right
    pane.setBackground(Color.white);
    return pane;
    public void actionPerformed(ActionEvent e) {
    numClicks++;
    label.setText(labelPrefix + numClicks);
    private static void initLookAndFeel() {
    String lookAndFeel = null;
    if (LOOKANDFEEL != null) {
    if (LOOKANDFEEL.equals("Metal")) {
    lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
    } else if (LOOKANDFEEL.equals("System")) {
    lookAndFeel = UIManager.getSystemLookAndFeelClassName();
    } else if (LOOKANDFEEL.equals("Motif")) {
    lookAndFeel = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
    } else if (LOOKANDFEEL.equals("GTK+")) { //new in 1.4.2
    lookAndFeel = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
    } else {
    System.err.println("Unexpected value of LOOKANDFEEL specified: "
    + LOOKANDFEEL);
    lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
    try {
    UIManager.setLookAndFeel(lookAndFeel);
    } catch (ClassNotFoundException e) {
    System.err.println("Couldn't find class for specified look and feel:"
    + lookAndFeel);
    System.err.println("Did you include the L&F library in the class path?");
    System.err.println("Using the default look and feel.");
    } catch (UnsupportedLookAndFeelException e) {
    System.err.println("Can't use the specified look and feel ("
    + lookAndFeel
    + ") on this platform.");
    System.err.println("Using the default look and feel.");
    } catch (Exception e) {
    System.err.println("Couldn't get specified look and feel ("
    + lookAndFeel
    + "), for some reason.");
    System.err.println("Using the default look and feel.");
    e.printStackTrace();
    * Create the GUI and show it. For thread safety,
    * this method should be invoked from the
    * event-dispatching thread.
    private static void createAndShowGUI() {
    //Set the look and feel.
    initLookAndFeel();
    //Make sure we have nice window decorations.
    // JFrame.setDefaultLookAndFeelDecorated(true);
    //Create and set up the window.
    JFrame frame = new JFrame("SwingApplication");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //final int width=300;
    //final int height=400;
    frame.setSize(600,900);
    SwingApplication app = new SwingApplication();
    Component contents = app.createComponents();
    frame.getContentPane().add(contents, BorderLayout.CENTER);
    //Display the window.
    frame.pack();
    frame.setVisible(true);
    public static void main(String[] args) {
    //Schedule a job for the event-dispatching thread:
    //creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
    }

    You still aren't using the "code" formatting tags as was suggested in your first posting in the forum.
    when i add the picture and the buttons go vertically down from the image,Well, this doesn't make sense since you are using a FlowLayout which means components will be displayed horizontally on a line, not vertically.
    If you need further help then you need to create a [url http://www.physci.org/codes/sscce.jsp]Short, Self Contained, Compilable and Executable, Example Program that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided. (ie. the code doesn't compile so we can't test it).

  • TS1538 I have tried everything but I can't connect my iphone to my laptop. It says that apple mobile device failed to be installed. I have read everything on the internet and did everything but still am facing the same problem. Can you please help me.

    I have tried everything but I can't connect my iphone to my laptop. It says that apple mobile device failed to be installed. I have read everything on the internet and did everything but still am facing the same problem. Can you please help me.

    Again without stating the trouble shooting steps you have taken, its hard to direct you with any information.
    Try a different port on the computer.
    Does the iphone beep when u plug it up. ?
    Plug iphone into computer and give it 3 to 4 minutes to see if it connects and is running slow.,
    Delete the apple mobile device from your computer.
    Upgrade itunes to newest version.
    Is you USB cord defective ?
    Any USB 3.0 on your system ? .
    Delete or Disable  any antivirus program on your computer ?
    I will tell u the problem is your computer not the phone.
    We could do this for hours.

  • HT1349 WHEN I TURN MY IPHONE 3S ON IT ASKS ME TO CONNECT TO ITUNES AND RESTORE. I HAVE DONE THIS 10 TIMES AND STILL GET THE SAME SCREEN. CAN ANYONE PLEASE HELP??

    WHEN I TURN MY IPHONE 3S ON IT ASKS ME TO CONNECT TO ITUNES AND RESTORE. I HAVE DONE THIS 10 TIMES AND STILL GET THE SAME SCREEN. CAN ANYONE PLEASE HELP??

    Has your phone been jailbroken?  If so, you will likely never get it to work again.
    You can try placing your phone in DFU mode (search google) and restoring.

  • I am not able to sync some videos and apps onto my iphone 3gs. it shows a sync error: 0xe8008001.i updated it but still i am getting the same sync error problem..please help.

    i am not able to sync some videos and apps onto my iphone 3gs. it shows a sync error: 0xe8008001.i updated it but still i am getting the same sync error problem..please help.
    aman

    Are you using Windows...?

  • When we using overflow-x and overflow-y in tbody its not working properly. In the previous version i.e. 3.7.1 its working fine the same coding....Please help me.

    ''Duplicate post, continue here - [https://support.mozilla.com/en-US/questions/828024]''
    when we using overflow-x and overflow-y in tbody its not working properly. In the previous version i.e. 3.7.1 its working fine the same coding....Please help me.

    See:
    *https://developer.mozilla.org/en/Firefox_4_for_developers#Miscellaneous_DOM_changes
    *http://www.cssplay.co.uk/menu/tablescroll.html
    A good place to ask questions and advice about web development is at the mozillaZine Web Development/Standards Evangelism forum.<br />
    The helpers at that forum are more knowledgeable about web development issues.<br />
    You need to register at the mozillaZine forum site in order to post at that forum.<br />
    See http://forums.mozillazine.org/viewforum.php?f=25

  • Windows thinks my itouch is a camera and itunes says this ipod can't be used because the software isn't installed - reinstall itunes.  i've done that and continue to get the same error.  can someone please help?

    windows thinks my itouch is a camera and itunes says this ipod can't be used because the software isn't installed - reinstall itunes.  i've done that and continue to get the same error.  can someone please help?

    (apologies for barging in, lllass.)
    Let's try a standalone Apple Mobile Device Support install. It still might not install, but fingers crossed any error messages will give us a better idea of the underlying cause of why it's not installing under normal conditions.
    Download and save a copy of the iTunesSetup.exe (or iTunes64setup.exe) installer file to your hard drive:
    http://www.apple.com/itunes/download/
    Download and install the free trial version of WinRAR:
    http://www.rarlab.com/download.htm
    Right-click the iTunesSetup.exe (or iTunes64setup.exe), and select "Extract to iTunesSetup" (or "Extract to iTunes64Setup"). WinRAR will expand the contents of the file into a folder called "iTunesSetup" (or "iTunes64Setup").
    Go into the folder and doubleclick the AppleMobileDeviceSupport.msi (or AppleMobileDeviceSupport64.msi) to do a standalone AMDS install.
    (If it offers you the choice to remove or repair, choose "Remove", and if the uninstall goes through successfully, see if you can reinstall by doubleclicking the AppleMobileDeviceSupport.msi again.)
    Does it install (or uninstall and then reinstall) properly for you? If so, does your device connect without that message now?

  • HT1420 I get en error message 42408. I have tried several times to activate my account but the same message keeps reappearing. Please help. I cant even sink my iPad or iPhone. Thanks

    I get en error message 42408. I have tried several times to activate my account but the same message keeps reappearing. Please help. I cant even sink my iPad or iPhone. Thanks

    After searching, found a few answers and tried one last thing-- allowing Safari to accept Cookies. I never use Safari so never changed any settings in it ever. However, I guess an update along the way turned off cookies in it and that was the blockage. Once I allowed Safari to use cookies I was able to redeem the gift card. SO, glad this board is here for these types of questions!!!!

  • Started downloading IOS8 24 hrs ago, still down loading now! Tried switching off/on with 2 button still the same. Can anyone advise please. Cheers

    I Want to stop download of iOS 8 and start again

    sorry, thought my question had been posted. I started downloading iOS 8 24 hrs ago, it is still downloading now, have tried off/on with 2 buttons but still the same can anyone advise please cheers

  • My ipad is saying ipad disabled connect to itunes. so I connected to itunes. i have already done the recovery and am still getting the same message before. Someone please help me!

    I have already tried to recover my ipad but it still keeps coming up that it is disabled and to connect to itunes. When i go to itunes it says that I require to put my passcode in on my ipad but i cant because its still disabled. Please help, I have no clue where to go from here. I though by recovering it that it would work but it didn't. Help! Thanks in advance.

    Did you do this?
    Recovery Mode:
    1. Turn off iPad. Press and hold the Sleep/Wake button for a few seconds until the red slider appears, slide to turn off.
    2. Connect USB cable to computer; leave the other end alone
    3. Press and hold the Home button down and connect the docking end of cable to iPad
    4. Continue holding the Home button until you see the "Connect To iTune" screen
    5. Release the Home button
    6. Open iTune (make sure you have the newest version of iTune)
    7. You should see "iTunes has detected an iPad in recovery mode"
    8. Use iTune to restore iPad
    Note: You need to be patient and repeat the above many times to recover your iPad

  • My MacBook Pro crashes when I go into Powerpoint slideshow mode and I get an error message to resave and give it another name.  I updated the powerpoint based on using the help update but get the same problem....please help!

    I updated to Mavericks and since then my powerpoint no longer works when I want to start the slideshow mode.  Help!

    http://answers.microsoft.com/en-us/mac/forum/macpowerpoint?tab=Threads

  • When I want to zoom in or zoom out with the mouse wheel and CONTROL button the letters get larger but remain within the same size paragraph and any pictures remain the same. I want the entire page to zoom.

    <blockquote>Locking duplicate thread.<br>
    Please continue here: [[/questions/866940]]</blockquote>
    I want the entire page to zoom in and out when I use CONTROL + mouse wheel. Now the letters get larger but remain in the same size paragraph and also the pictures stay the same.

    It is indeed scandalous that Apple sells useless scanned music scores. There is a warning when you chose to download music tabs or notes but it doesn't say that the score lines are very small and cannot be zoomed. I spent $30 on two books but cannot really use them on my MBA as you cannot zoom except for the double click which only works page per page and is only a small improvement.
    The only way I can use the score more or less is on my ipad in landscape mode by increasing the font size to the max. The music score then becomes wider and you can read 2-3 lines per page without glasses.
    If you could transfer the file to the pdf  "side" of the library in ibooks the zoom would work..
    What does work is using the accessibility zoom mode option+command+= to zoom and then option+command+\ to smooth the picture but then your whole display desktop etc. are zoomed in.

  • Making checkboxes/radio buttons the same size?

    Hi,
    I'm trying to figure out a way to make all my checkboxes and/or radio buttons the same size on a document. I've tried right-clicking the button, to check the properties but it's not giving me much. When I tried to copy-paste the checkbox, it will automatically assign the same properties of the copied checkbox to the pasted one - which is annoying because if I check the first box, the second box is automatically check too! Not what I want
    Any ideas on how I can fix this?
    Thanks a million!

    For Acrobat 9, select all of your checkboxes or radio buttons. With them selected, right click Set Fields to Same Size and choose Both. The fields will size to match the size of the last item you selected.

  • How can two pictures of the same size still appear to be a different size? (Photoshop CS6 problem)

    I called the big webdesign file "(X)" and the image I wanted to paste in it "(Y)",
    so that you won't be confused when you read it.
    What Happened
    For the design of a webpage, I made a photoshop-file(X) with a lot of squares(X). These squares(X) had the size 9,42×9,42 centimeters.
    I measured the squares(X) carefully and also made sure the size was in centimeters, so I am sure that the size was 9,42×9,42 cm.
    My plan was to fill the squares(X) with pictures(Y). I had a map on my computer with a lot of square-sized JPG-images(Y) in it. All I had
    to do was open the pictures(Y) in photoshop, change the size into 9,42×9,42 centimeters and copy+paste them into the squares(X)
    of the webdesign. I did this before and it worked perfectly.
    But then, I opened one of the images(Y) and when I wanted to resize it, the resize-tool said it was only 3,25×3,25 centimeters big.
    I thought it was strange, so I copied+pasted it into the design-file(X) with all the squares(X) that needed to be filled. Allthough photoshop
    had told me that the squares(X) in the file were 9,42×9,42 centimeters big and the image(Y) I resized was 3,25×3,25, the "small" image(Y)
    turned out to be bigger then the squares(X). And when I resized the "small" image(Y) into 9,42×9,42 centimeters, it was even bigger
    than it was before. How can this be, and how can I still make the images(X&Y) the same size?
    What I already tried
    - I made the file of the webdesign(X) with all the squares(X) into one layer, copied the file(X) and opened a new file(X) with the same
    measurements of the old file(X). I also changed the resolution of the file(X) into pixels/centimeters instead of pixels/inches.
    Then I pasted the image(X) of the old file into the new file. I didn't work; the image(X) that I pasted in the new file was bigger and
    when I pasted the other picture(Y) in this image, the same problem was still there.
    - I also opened the picture(Y) in photoshop, made a screenshot of it and then pasted the screenshot into paint. With paint I cropped
    it again and saved it as a JPEG-file. After that, I opened the image (Y) in photoshop again. It now had the size of 11,27×11,27 centimeters.
    Then I resized the image(Y) into 9,42×9,42 cm, but it still wasn't as big as the squares(X).
    Could you help me please?
    I really don't understand why this problem is happening and I can't think of a solution because I am still quite unexperienced with photoshop
    and I also couldn't find the answer on the internet. I assume the solution is very simple, but I haven't found it yet allthough I have to finish this
    project soon and I also have to use the image(Y). So any help would be very appreciated.
    Thanks,
    Simone

    You need to understand the basic of a digital image.
    Image is recorded as pixels and image is a rectangle so many pixels wide and so many pixel high.   Pixels do not have a fixed size. The images resolution setting defines the image current pixel size.
    So for example if you have and image that is 300 pixel wide and 200 pixels high and set its dip resolution to 100DPI the image size is 3" wide and 2" high.  Set its dip setting tp 300DPI the image size becomes 1" wide by 2/3" high.  Both the 3" x 2" and the 1"x2/3" images have the same 60000 RGB Colored Pixels.
    Web pages are sized to to be so many pixel wide and so many pixel high.  Often the height is not enforced scrolling is used when viewing. 
    However image for web pages often must not exceed so many pixel wide and high for displays have a fixed resolution and a fixed number of Pixels. You want images to fit on users displays.  Users use different displays some have high resolution displays and other have low resolution displays with far fewer pixels then high resolution displays.
    Web Image are normally image that have been interpolated down in number of pixels a resampled large image so that web image will fit on a low resolution  display with limited number of pixels. The image size the user see depend on the display they are currently using. A low resolution display's image will be much larger then the same image displayed on a nexus 10 with a 300dip display. Cheep low cost Desktop LCD have a 84DIP resolution, large high cost desktop displays are not be much higher in resolution somewhere near 108DPI.   Tablets, Laptop and Phones can have much higher resolution like the nexus 10 300DPI IPS display

  • How to resize watermark to be the same size for vertical/horizontal images?

    I am using File -> Place menu to place my watermark onto the images. 
    No matter what I try so far, the absolute size of the watermark comes out different Portrait/Landscape images.
    Watermark is smaller on Portrait and larger on Landscape images.  I tried resizing writing in the number of pixels during the File->place command, but no luck.  Photoshop resizes the watermark based on the percentages, and I don't know why image orientation matters. 
    ideally I want my watermark to be the same size, and I can use absolute pixel dimensions if needed.  How do I do this?

    Hi Doug - What exactly are you trying to do? Is the third
    child being added dynamically, and you want it added above the
    first child? If so, you can use the addChildAt() method when adding
    the child to the container. addChildAt() takes an index and the
    child object is added at that index and all other children are
    reshuffled to maintain the ordering. IE:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="vertical">
    <mx:TitleWindow layout="vertical" id="tw">
    <mx:Button id="a" />
    <mx:Button id="b" click="go();"/>
    </mx:TitleWindow>
    <mx:Script>
    <![CDATA[
    private function go():void
    var c:Button = new Button();
    c.label="new";
    tw.addChildAt(c, 0);
    ]]>
    </mx:Script>
    </mx:Application>
    Does that help, or am I misinterpreting what you're trying to
    do?

Maybe you are looking for

  • HP Photosmart 5520 Not Printing Black; I'm Out $58.99 For HP Ink Cartridges I Can't Use

    So after my printer stopped printing in black ink, I came to the forums to research the problem. I tried all of the recommended/suggested "fixes" to no avail. Upon realizing that this is a known issue with these printers, and after speaking with an H

  • How to find my ipod ?

    Hello, I dont remember where to go to find my ipod which is somewhere in my house, can someone indicate me how to do it ?

  • Pending orders SD

    to generate report in ABAP query to get the list of Sales orders for which it has to show the orderd qty and actual Delivered Qty.if i join the tables of Sales and delivery.its not showing any data when i run the query.? Rohit

  • 802.1x Machine and User Auth Vlan assignments

    I have machine and user auth working between Win2K PC and ACS 3.3 but not sure how to best use the Vlan assignment feature. I use Vlans for different departments and if I assign a vlan in ACS to a machine when it authenticates but the user is assigne

  • GPS App to track my route

    I know in many apps you can define your route and it tells you where to go, but I need an App to do the opposite. I want it to record my position as I go and then show me in the Map where I have been and the route I've taken. Does anybody knows any a