Set location of component in a container

I'm looking for a way to exactly specify the location for a component in a container.
For example let's say i have some JPanel and i want to add a JButton to it at coordinates x=100, y=50.
Is this even possible?
All the lay out managers seem to prevent this because they auto-arrange the components in the container.

You can try to use something like this:
import java.awt.Container;
import java.awt.Insets;
import java.awt.Dimension;
import javax.swing.JButton;
import javax.swing.JFrame;
public class AbsoluteLayoutDemo {
    public static void addComponentsToPane(Container pane) {
        pane.setLayout(null);
        JButton b1 = new JButton("one");
        JButton b2 = new JButton("two");
        JButton b3 = new JButton("three");
        pane.add(b1);
        pane.add(b2);
        pane.add(b3);
        Insets insets = pane.getInsets();
        Dimension size = b1.getPreferredSize();
        b1.setBounds(25 + insets.left, 5 + insets.top,
                     size.width, size.height);
        size = b2.getPreferredSize();
        b2.setBounds(55 + insets.left, 40 + insets.top,
                     size.width, size.height);
        size = b3.getPreferredSize();
        b3.setBounds(150 + insets.left, 15 + insets.top,
                     size.width + 50, size.height + 20);
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
    private static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new JFrame("AbsoluteLayoutDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //Set up the content pane.
        addComponentsToPane(frame.getContentPane());
        //Size and display the window.
        Insets insets = frame.getInsets();
        frame.setSize(300 + insets.left + insets.right,
                      125 + insets.top + insets.bottom);
        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();
}pane.setLayout(null) will give you what you want.

Similar Messages

  • Help with locate a component in a container

    Hello everyone,
    I want to set a JButton in a specific location in a JPanel. But I have no idea about this.
    I tried to use JButton.setLocation or setBounds(). But it doesn't work.
    import java.awt.*;
    import javax.swing.*;
    public class test1 extends JFrame{
         JButton b=new JButton("test");
         JPanel p=new JPanel();
         test1(){
              b.setBounds(100,100,20,20);
              p.setBounds(0,0,200,200);
              p.add(b);
              getContentPane().add(p);
              setBounds(0,0,200,200);
              show();
         public static void main(String args[]){
              new test1();
    What is the problem.
    Thank you

    test1(){
    getContentPane().setLayout(null);
    b.setBounds(100,100,20,20);

  • Trying to open a page in IE-tab using javascript, script type="text/javascript" window.location.href="chrome://coralietab/content/container.html?url=0,myurl" /script Error:Component returned failure code:0x80004005 (NS_ERROR_FAILURE) [nsIDOMLocation.href]

    I am trying to open a page in IE-tab using javascript like this, <script type="text/javascript"> window.location.href = "chrome://coralietab/content/container.html?url=0,myurl" ;</script>.Error occured : [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMLocation.href]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame ::myurl :: load :: line 234" data: no] I have IE-Tab plug-in installed..when I open the same link manually in mozilla,it works fine and page gets opened in Ie-tab.

    The only way this might be possible is by using the HostContainer object
    to access the HTML page and do it from there.

  • How to set a Swing component as Modal window on a SWT Component.?

    How to set a Swing component as Modal on a SWT Component.I mean, I have a window (SWT Container) with some menu items.
    When I click on one menu item then i will get one new Swing Window.
    When creating the new frame I had passed Modal value as TRUE in the constructer.Now child is not behaving as Modal Window.I mean I am able to go to parent window even though the child window is opened as a Modal Window.This is only happened when I double click on the Title Bar of the Parent Window.
    If I try to click on any other part of the Parent Window except Title bar ... the child window is working as a Modal Window.
    Can any one suggest me to solve this one !!

    int this case, do this :
    JFrame f = new JFrame("Authentification");
    f.getContentPane().setLayout(new BorderLayout());
    f.getContentPane().add(myJPanel, BorderLayout.CENTER);
    f.setBounds(x,y,w,h);
    f.setVisible(true);
    Where myJPanel is the Panel you developped.

  • Set location of components and reduce the size

    I want to resize JavaFX component and shrink the components which are next to it. Here is the result which I get:
    When I click on the angle of this component I can resize it down and right.
    http://i.stack.imgur.com/jqoNW.png
    The components which are next to it are pushed down and right. Part of them are behind the visible part of the screen.
    http://i.stack.imgur.com/rsi0L.png
    All components are placed in BorderPane,VBox,HBoxand againBorderPane. I don't want to allow components to move. I want to shrink them and use Scrollpane` when their size is reduced. Can you give me some hits how to solve these two problems?
    Ref javafx 2 - Set location of components and reduce the size - Stack Overflow

    I did something similar the other day. Based on the resizing of the scene I adjusted the position.
    widthProperty().addListener(new ChangeListener<Number>() {
        @Override public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneWidth, Number newSceneWidth) {
            widthChange((Double)oldSceneWidth, (Double)newSceneWidth);
    heightProperty().addListener(new ChangeListener<Number>() {
        @Override public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneHeight, Number newSceneHeight) {
            heightChange((Double)oldSceneHeight, (Double)newSceneHeight);
    You should be able to do something similar, when you add a change listener to your component and handle the resizing of the other components.
    What I don't understand is why you would need a scrollbar, when the components shrink down. I would think it would be the other way round.

  • Logic plug in setting locations?

    Hi, I'm still kind of new to Mac's and a few weeks ago I was cleaning up and re-orginizing some of my folders. I wasn't aware that mac's are much, more folder specific than a windows OS?  While moving various files/folders when cleaning/orginaizing, I must have moved some of my 3rd party logic folders?  I didn't move any of the actual au componnets they are still in the correct place so that logic can locate them.  Only problem now they can't seem to locate them even though the components show in the correct component folder?  Did I mess something up by moving folders around?  I had assumed as long as I didn't mess with things like the actual component and preset folders that it didn't really matter if I moved I guess what you would call the plugins' main root folder, if that sounds right? 
    Appart from probably having to trash everything and re-install is there anything I can do?  Perhaps a quick fix like ,"just drag/move all my 3rd party plug ins to such and such folder?  I don't understand why in a mac that you can't just create a new folder and  call it, "logic plug in related files"  for example;  and move all of your 3rd party plug ins over to it(except for the actual commponents of course)?  Or can you?  I guess I'm just generaly copnfused about plug in setting locations for both 3rd party and non.  Am I correct in saying that plug in setting location folders can actualy vary from 3rd party to 3rd party plug ins? If this is true what a pain! Like I said I probably have no other option except to delete and re-install?  I wish my mac could be brought back to how it was before I messed with any folders!  Trouble is to free up hard drive space I got rid of a bunch of time machine backup so I don't think I can go back to a previous state before I moved any stuff around:(
    I just don't get it though and its very annoying.  For example, I have a lexicon reverb bundle, always worked great;the correct components are still in the correct audio/plug in/commponent folder, but ever since I moved some root plug in files around the lexicon plug ins no longer show up.   They don't even show in the AU manager,which is frustrating becasue I can go to the component folder and they are physicaly there!  Why would it not even show in the AU manager if the component is physicaly in the right place still?Help please...Wha did I do/What do I do?
    Thanks everybpody,
    Mike

    A line across a plugin usually comes from trying to insert a mono plugin on a stereo track of vice versa. Could this be your problem.
    I've rearranged my project folders many times without any problem whatsoever. Have you saved your projects with Assets?
    R

  • The backup location does specified does not contain any backup. Specify another backup location.

    We have our server set to backup to an internal HDD (E:), and then copy all the files in E: to different locations for storage (a NAS for instance).  I scheduled a copy to a USB drive, but I can't get the recovery wizard to see the backup it now contains. 
    I choose "A backup stored in another location" and then "Remote shared folder", as the USB (G:) does not show up in Local drives.  I now need to enter a UNC (it won't accept the "G:\" path), so I shared the USB drive and
    enter "\\SERVER\G\2014-09-23", which is the path to the parent of the WindowsImageBackup folder on the USB drive.  At this point I get the above error "The backup location does specified does not contain any backup"
    All the files look to have copied OK, and have the same Date Modified as on the server: as far as I can tell it's identical, and yet it won't mount. Help?

    Hi,
    I would like to confirm the exact backup process:
    When creating the backup, are you choosing "local drives" and then "G:", or Remote shared folder and then \\server\g\folder?
    If it is a network path, could you restore it with \\server\g\folder instead?
    If you have any feedback on our support, please send to [email protected]

  • I can't run itunes or install updates now due to teh MSVCR80.dll file not found and APS Daemon.exe being nable to locate a component ofn Windows vists.  A MS user suggested uninstalling all Apple programs.  I did this but could not uninstall the Apple Mob

    I have been getting error messages  .n MS windows the APS Daemon ,exe is unable to locate a component and the itunes updates and program failed to start because MSVCR80,dll was not found.  As advised I have uninstalled all Apple Inc. programs except the Apple Mobile Device program.  Then I reinstalled itunes but still get the errors and can't run itunes.  Advice....

    See Troubleshooting issues with iTunes for Windows updates.
    tt2

  • Can we set a default value for the container variable in BPM?

    Can we set a default value for the container variable.?
    Suppose if i have a loop step and i have given a container variable i=5 as end condition.What value will it take during its first execution?Can we set the value for container before a recieve step?

    Hi
    Define Container Variable of Type integer and Category Simple Type .Use Condtion in Loop.
    In Container Operation Step Assign value and Use Expression to
    Increase or Decrease Valus according to your operation.
    look Pattern 4 in this blog to understand Container Operation
    /people/sharathchandra.girmaji/blog/2008/09/11/bpm-with-patterns-explained-part-1

  • How to set a Swing component as Modal on a SWT Component?

    How to set a Swing component as Modal on a SWT Componen?.I mean, I have a SWt Component window and from that window I am displaying a SWING Component Modal window.
    The problem is my swing window is not working as Modal always.
    When I opened the swing window from SWT window,swing window is working as Modal.But if Idouble click on Menubar or Title bar of the SWT Window then my Swing window goes back.If I click on any other part of the SWT window.. then once again Swing window is working as modal.
    Can any one suggest me to solve this?
    I think this is isuue related with Swing over SWT..

    pradeep.rajadurai wrote:
    I want set the JTable as a background of jframe or jinternalframe , how it is possible One way that may work, you can always extract the image from a rendered JTable and then paint the same image into the JPanel that holds your components via it's paintComponent method, then added the JPanel to the app's contentPane.
    give me simple pgmIs English your second language? Because if so, please understand that this demand can be taken by some as rude.

  • Get Siri to set location reminders (using multiple reminder lists)

    I found a way to get Siri to set location reminders using multiple reminder lists (but you can just use one list too):
    First make additional lists in the reminder app: click list button (the lines on the left) > edit > create new list > done. Make as many as you want. I have grocery, home, personal, business, family.
    Let's say you want a reminder to pick up apples when you get to the apple store. You must add the location in your contacts to your name in contacts.
    Do the following:
    In maps app find the location with search.
    Tap the blue arrow > Add to contacts > Add to existing contact
    Choose your name in contacts. It will be added under your address for home or work so you will need to edit it:
    Click Edit.
    Click on the small label on the left of the new address - it will just say "address"
    Scroll to bottom of page and click on Create custom label
    Enter the location name like "Apple Store". Click Done.
    Important Note: You will need to delete the url it adds under your home url section and maybe other things it messes up with the new contact info instead of yours - so check all the fields each time you do this.
    To make a location based reminder using a specific list you must open that list yourself - Siri will not open it for you.
    Example:
    Open grocery list yourself in the reminders app
    Tell Siri something like: "remind me to pick up apples" (Do not mention the location yet - if you do it will not work)
    Siri will ask: "When should I remind you?"
    Say: "When I get to the apple store"
    Siri will say she will remind you and you will see the location reminder in the grocery list.
    This is how it works for me but if you know an easier way let me know! This is beta so I'm sure it will get easier.

    I have one thing to add.  You don't have to open the list manually.  Tell Siri:  "Add to my <listname> list".  For example, if you have a list named "Work", tell Siri:  "Add to my work list".  Siri will reply, "What should I add to your 'Personal' list?
    and you can continue from there. 
    There is a syntax for doing all this in one sentence, but I find it only works about half the time. Too many fields for Siri to parse in her current Beta stage
    /d

  • Set Location of individual text box - report design

    Post Author: sonjeeva
    CA Forum: Crystal Reports
    Hi Guys,
    Is it possible to set location of an individaul text box to be at the end of report? I know if I have this at end of report area it would work. But my report has a sub report in end of report area and the text box doesn't appear at the end of both reports.
    Cheers
    Sonny

    Post Author: kcheeb
    CA Forum: Crystal Reports
    If you are creating the report through code (C#, VB etc.) you could get the location/size of the subreport and then set the text box location based on those parameters.
    I don't think it's possible from within the Crystal report designer itself. At least I couldn't find a place to do this.

  • Set location  - CR 8.5 vs CR XI

    I didn't find exact answer to my question.
    Short overview. CR layouts are used in ERP system just reading and formating data from SQL 2005 prepared by special stored procedures. Main clue is to use the same layout for production and test databases (with many different names).
    After link new table in CR 8.5 there was only a need to change 'Set location' -> 'Location: Table' from <database name>.dbo.<table name> to <table name> and it works fine.
    Now I'm switching CR layouts to CR XI R1 SP4 (the newest one supported by ERP) but can't find the same possibility like described for 8.5. All new tables based on OLE DB have 'catalog: <database name>' which I cant change. Even if 'Initial catalog' is empty there is always database name in table properties which causes building queries like 'select ... from <database name>.dbo.<table name>' instead of <select ... from <table name>'.
    How to enable behavior known from 8.5 in XI?

    Solution:
    Entering manually table name in 'Overridden Qualified Table Name' without database name solves the problem.

  • Setting default parsys component and packaging them

    Hi,
    Is anyone familiar with how to enable default components to appear in a certain parsys?
    Usually what I would do is manually go into Design Mode, find that certain parsys that I want to edit, click on the Edit, and locate the component under the "Allowed Components" list and check the box corresponding to enabling that component. I found out that when a component is checked to appear in that certain parsys, it will also automatically create a node (eg. mynode) at "/etc/design/default/jcr:content/mynode". And within this node, there will be a property called "components" that will determine what component will appear in this parsys. So I am assuming that this is the way to enable components in the parsys through the codes (without having to manually enable them at that webpage).
    After which, I will package all the contents of "/etc/design/default/jcr:content/mynode" and proceed to deploy it in my client's server. The problem now is, the contents once installed (in client's server), is deleted once again. I suspect it has something to do with it being under jcr:content. Is my assumption right? And how do I solve this? And if I package "/etc/design/default" and deploy it, it seems to work fine. I cannot deploy the whole default folder though. This is because, I cannot confirm if there are other projects that adds their "default components" under that folder. By putting only my "/etc/design/default", there might be a possibility of removing my client's other project's default components.
    To summarise, what I want is to package the contents of "/etc/design/default/jcr:content/mynode" and place it in my client's server, and make sure that it is not deleted (Assuming editing the contents of "/etc/design/default/jcr:content/mynode" is the way to create default parsys components).
    Any detailed help will be appreciated! Thanks!

    How do I create a site page from "http://localhost:4502/miscadmin#/etc/designs"? I am a little confused over here.
    When I refer to the geometrixx site example, I can see that the "components" property inside "/etc/designs/geometrixx/jcr:content/examplepage/parsys" has my enabled component's path in it. But when I duplicate the exact same structure into "/etc/designs/myproject/jcr:content/myprojectpage/myparsys" in its components property, the component that I want to enable doesn't show up. Even when I created a new page, it doesn't show up. But when it is created in "/etc/designs/default/jcr:content/myprojectpage/myparsys", it works.
    So as you can see, somehow my projects are directing the path to "/etc/designs/default", instead of "/etc/designs/myproject". How do I change the direction path? There seems to be no place to configure this.

  • IB52 Enhacement - Locating Modified Component

    Hello,
    I am developing enhancement to IB52 transaction. Whenever user changes business partner of component and click on save. I need to identify which component is modified and update corresponding components contracts business partner. I have modified IBASE_SAVE badi but I could not able to locate which component is modified by user. Is there any other badi and function module which will provide me details of which component is modified by user during IB52 transaction modification?
    Regards
    Prasad Naik

    Hi Prasad,
    Thanks for the time spending on the query.I have a req on Ibase to copy partner number to external id and partner name to description of ibase header for which I am implementing BADI IBASE_SAVE and got all details but unable to find the functionmodule to update the data.
    Can u pls help me in this regards as u have worked and solved ur issue.
    Its would be gr8 help and appreciated .
    Thanking you,
    sree.

Maybe you are looking for

  • I want to create a Ajax based Chating application using java .

    hi . I want to create an chating Application , and ajax based chatting application using java as my server side language ..i have some idea about it .. but one thing that i m not understanding is that how i will communicate with other users because e

  • Need some clarification on Replacement Path with Variable

    Hello Experts, Need some clarification on Replacement Path with Variable. We have 2 options with replacement path for characteristic variables i.e. 1) Replace with query 2) Replace with variable. Now, when we use  "Replace with variable" we give the

  • BackGround Task to execute report is 'IN PROCESS'

    Hello Experts, I have developd a workflow where i have added a task which will execute a report in background as code below - SUBMIT rhakti00      USING SELECTION-SCREEN 1000     WITH SELECTION-TABLE rspar       AND RETURN. The output of the report i

  • How to back up a CD that shows as 2 volumes?

    I have a CD for an app on my old PM 7300 and to use the multimedia part of it, I have to insert the CD. I noticed the disc isn't as shiny as it used to be and I want to back it up just-in-case. If I put it in the modern PB the CD shows as 2 volumes.

  • XI 3.0 versus XI 2.0

    Hi, can I find somewhere the main difference between XI 3.0 an d XI 2.0? THX Matt