Mystery: GridBagLayout on Panel1 lost after adding Panel1 on Panel1

This is puzzling me.
The buttons b1 and b2 should appear at the bottom because "c.anchor=GridBagConstraints.PAGE_END;"
Instead it appears at the centre. The problem only appears when Panel containing the GridBagLayout is added to another Panel.
If anyone knows the answer to this?...............Is it a bug?
using java SDK1.4.
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
public class TestPanel extends JPanel {
public TestPanel() {
super();
setBorder(BorderFactory.createTitledBorder("p"));
GridBagLayout glayout = new GridBagLayout();
GridBagConstraints constraints = new GridBagConstraints();
JPanel p1 = new JPanel();
Dimension size = new Dimension(100,300);
p1.setPreferredSize(size);
p1.setBorder(BorderFactory.createTitledBorder("p1"));
p1.setLayout(glayout);
JButton b1 = new JButton("b1");
JButton b2 = new JButton("b2");
addComponent(p1, glayout, constraints, b1, 0, 0, 1, 1);
addComponent(p1, glayout, constraints, b2, 1, 0, 1, 1);
add(p1);
private static void createAndShowGUI() {
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("buttons suppose to be at bottom of Panel");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
TestPanel newContentPane = new TestPanel();
newContentPane.setOpaque(true);
frame.setContentPane(newContentPane);
frame.pack();
frame.setVisible(true);
private void addComponent(JPanel p, GridBagLayout g, GridBagConstraints c,
Component component, int row, int column, int width, int height )
c.gridx= column;
c.gridy=row;
c.gridwidth=width;
c.gridheight=height;
c.fill=GridBagConstraints.NONE;
c.anchor=GridBagConstraints.PAGE_END; ///Why anchoring not working?
g.setConstraints(component, c);
p.add( component );
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}

Found the problem. forgot the weights. Thanks.
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
public class TestPanel extends JPanel {
public TestPanel() {
super(new GridLayout(0,1));
setBorder(BorderFactory.createTitledBorder("p"));
GridBagLayout glayout = new GridBagLayout();
GridBagConstraints constraints = new GridBagConstraints();
JPanel p1 = new JPanel();
Dimension size = new Dimension(100,300);
p1.setPreferredSize(size);
p1.setBorder(BorderFactory.createTitledBorder("p1"));
p1.setLayout(glayout);
JButton b1 = new JButton("b1");
JButton b2 = new JButton("b2");
setLayout(new GridBagLayout());
addComponent(p1, glayout, constraints, b1, 0, 0, 1, 1, 0, 0);
addComponent(p1, glayout, constraints, b2, 1, 0, 1, 1, 1, 1);//adding weights
add(p1 );
private static void createAndShowGUI() {
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("buttons suppose to be at bottom of Panel");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
TestPanel newContentPane = new TestPanel();
newContentPane.setOpaque(true);
frame.setContentPane(newContentPane);
frame.pack();
frame.setVisible(true);
private void addComponent(JPanel p, GridBagLayout g, GridBagConstraints c,
Component component, int row, int column, int width, int height,
int weighty, int weightx)
c.gridx= column;
c.gridy=row;
c.gridwidth=width;
c.gridheight=height;
c.anchor=GridBagConstraints.NORTHWEST;
c.weighty = weighty; //added................
c.weightx= weightx; //added....
p.add(component, c);
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}

Similar Messages

  • Songs lost after adding/changing playlist

    My girlfriend has a ipod mini formatted for windows usage.
    I have a g4 powermac. From the start there no problems whatsoever, everything was configurated perfectly so that the ipod could be connected to windows and mac machines.
    The last time something strange happened. I made some new playlists on the ipod and moderated one by adding some songs. The next day she told me that several songs were missing at random in a couple playlists. Other songs were skipped through like they were 0 second duration.
    What is the problem here and how can I solve it?

    I'm on windows, and have exactly the same problem.The program won't add any more songs after 30 have been added. I have tried to change the playlist's name, that didn't help.I've deleted the playlist and created one with the same name, but the problem still persists. It's really annoying because none of my other playlists have this issue.

  • JLabel Image Icon lost after added to JLayeredPane

    This is probably that is relatively trivial:
    I have a created a simple class that extends a JPanel
    Within the JPanel I add a JLayeredPane
    Within the JLayeredPane I add two JLabels
    The two JLabels are image placeholders (set using the *.setIcon method)
    Images are set in the JLabels using a public method setImage (for each label respectively)
    In the super class that invokes this, the object (myPanel) with the JPanel shows the panel fine along with the JLayeredPane, anyways this is the problem say "myPanel" calls the method setImage (myPanel.setImage...), the image is set in the JLabel componenent in the JLayeredPane but it seems to get erased when a windows goes over!
    What am I doing wrong?
    Thank you for your time.

    import java.awt.*;
    import javax.swing.*;
    public class Layer_Test extends JFrame {
        public Layer_Test() {
            setTitle("Layer Test");
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            setSize(400,300);
            setLocationRelativeTo(null);
            getContentPane().add(new MyPanel(), BorderLayout.CENTER);
        public static void main(String args[]) {
            new Layer_Test().setVisible(true);
    class MyPanel extends JPanel{
        MyPanel(){
            layeredPane = new JLayeredPane();
            label_1 = new JLabel();
            label_2 = new JLabel();
            layeredPane.setPreferredSize(new Dimension(300, 200));
            label_1.setIcon(new ImageIcon(MYPATH+"toolbarButtonGraphics\\general\\About16.gif"));
            label_1.setBounds(0, 0, 16, 16);
            layeredPane.add(label_1, new Integer(1));
            label_2.setIcon(new ImageIcon(MYPATH+"toolbarButtonGraphics\\general\\Copy16.gif"));
            label_2.setBounds(0, 100, 16, 16);
            layeredPane.add(label_2, new Integer(2));
            add(layeredPane);
        private JLabel label_1, label_2;
        private JLayeredPane layeredPane;
        private final String MYPATH = "C:\\Documents and Settings\\Uhres Andr�\\Mes documents\\";
    }

  • Lost sound in some film clips when finishing project.  Using iMovie 11, after adding music to photo section, could not get sound back in 2 film clips at end of movie.  Beginning clips ok. How do I restore sound? Thx.

    Lost sound in some film clips when finishing project.  Using iMovie 11, after adding music to photo section, could not get sound back in 2 film clips at end of movie.  Beginning clips ok. How do I restore sound? Thx.

    Everything in your project will be exported when you use the share menu.
    If you want to export only half, I suggest that you
    1) Select the project in the Project Library.
    2) Click FILE/DUPLICATE PROJECT
    3) Give the duplicate a name, like Project A snippet.
    4) Open the duplicate project in the Project editor and delete the segments that you do not need.
    5) Then Share.
    You mentioned surrounding a portion of the clip you were editing in Yellow. Once you do this, you should right-click and then select either DELETE SELECTION, TRIM TO SELECTION, or one of the other options available. That is a key tool in editing.
    You mentioned MPEG Streamclip. I agree that MPEG Streamclip is a great tool.

  • User Settings lost after session is released

    I am having a problem with the User settings being lost after the user logs off the system.
    menu settings, fields displayed in Marketing  Documents,  displayed User Defined fields and the
    sequence of User defined fields get lost after the session ends.  This does not happen to all users,
    just some users.  The users that keep losing their settings keep losing their settings,  the ones that do not have a
    problem seem never to have a problem.
    has anyone else experienced this problem and if so, how has it been resolved?
    Thanks in Advance!!!
    Dana

    Dana,
    You may check these threads first:
    change in form settings
    Re: Settings don't seem to "stick" after being added from the Form Setttings
    Re: 2007A PL42 and Windows Roaming Profiles
    Form settings not saving
    Thanks,
    Gordon

  • ITunes jacked up album art after adding music to iPhone

    After adding some new music to my phone last night, I noticed several files either lost the album art or it was wrong altogether.  This has happened before and it took several frustrating hours of documenting which files were messed up and correcting the album art.  But when I corrected the discrepancy, others that had the right artwork originally got messed up.  So I had to constantly check and recheck to make sure the music had the right art.
    The funny thing is, in iTunes the album art 'appears' correct under the iPhone device section.  It's just wrong when you physically look at the phone.  Do I need to go through the entire list of songs on the phone and delete every piece of album art and start all over again?  Just so I don't have to go through 5 or 6 iterations before iTunes gets it right?
    We're dealing with 1s and 0s here so what causes iTunes to mess this up?

    I am having the same issue. I recently update my mac and then want to update my iphone. I notice my art album on my iphone is all mess up. I check my music on iTunes the art album are correct. What am I suppose to do to correct this problem. This problem just happen yesterday (10/30/2013). Please help because I don't want to go throughout my entire music when it's apple fault..please advise on what to do. Thanks

  • After adding folders to iTunes library, now have duplicates of each song

    I store all my music on a separate drive, M:\
    I have a specific file structure setup that has worked for me for years, M:\Artist\Album
    I recently received an iPod for my birthday, and started using iTunes. After adding my music drive (M:\) for inclusion into the library (without "keep..." and "copy..." selected, as to keep my current file structure intact), when selecting "File->Display Duplicates" just about every song in the library has a duplicate, one in the original folder "M:\Artist\Album", and another in "M:\Playlists\..\Artist\Album". I understand that basically somehow iTunes glitched and started in the "M:\Playlist" directory when adding to the library at some point, however I am at a loss as to how. In my actual folders I only have 1 copy of each song, so basically iTunes is making a symbolic link to each song and adding it into the library as a separate song.
    I have over 9000 (must...resist...meme...) songs in my library, and removing and restoring takes quite a while. I'm pretty sure I'm going to have to do this at least once now, but any ideas as to why or advice on how to avoid this particular problem in the future?
    I am pretty set in my ways of my current file structure, since I don't use iTunes as my primary media software, so I would prefer to not have to resort to succumbing to just letting iTunes handle everything the way it wants (I pretty much hate that).
    Thank you for any suggestions you may have.
    EDIT: Is there a way to have iTunes rename/move files when adding to its library to specific folders via custom rules based on ID3 information (i.e. WMP rip settings)?
    Message was edited by: kaziekama

    If you have "Keep..." and "Copy..." unchecked, iTunes will simply reference the existing file, and will not change your file structure, as you correctly note.
    I'm fairly sure that some other program is operating on your files. The "Playlists" folder that you mention has nothing to do with iTunes. On my PC, only Windows Media and Roxio use it.
    To your question +"Is there a way to have iTunes rename/move files when adding to its library to specific folders via custom rules based on ID3 information (i.e. WMP rip settings)?"+ the answer is no. When iTunes rips a CD, it names the files as track number and title, with no option to do differently. And as far as placing the ripped files, they go in Artist/Album, with no option to do differently. As full-featured ripping programs go, iTunes is not even in the race.

  • Hyperlinks from other placed indd documents or pdfs getting lost after export to PDF

    after upgrade vom CS 5.5 to CS 6: hyperlinks from other placed indd documents or pdfs getting lost after export to PDF
    I tried all options for the as well known and working export options

    after upgrade vom CS 5.5 to CS 6: hyperlinks from other placed indd documents or pdfs getting lost after export to PDF
    I tried all options for the as well known and working export options

  • How do I set up my Imac after adding a SSD along with my existing HD

    How do I set up my Imac after adding a SSD so that my system and apps are on the SSD and everything else is on the HD?  I am using mountain Lion.  I want to make sure I can still do Time Machine backups. 
    I was planning on first formatting the SSD and then using Migration Assistant to copy the System and the Library and the Apps over.  Where it gets confusing is the User account where some of the items will be on the SSD but I want all my folders to be on the HD.  Do I just not copy over that other stuff and once I restart from the SSD it will know where all the folders are?  Is there anything I need to know about setting up a time machine backup after that?  Will the backup I had from the one drive have to be erased and start a whole new backup?
    I just want to do this right so I don't have some major problems.
    Thanks for any help.
    Michael

    time machine backed up your whole system data/everything in time machine hdd.
    you want to use ssd over hdd so you need to put new mac os x in ssd.
    then copy all the stuff that you want to put in ssd.
    from my point of view put the mac os x and other application in ssd and leave other data in hdd.(music,movies,etc....)
    more info about time machine : http://support.apple.com/kb/ht1427

  • What is the expected behavior in a zone after adding a new static route in Solaris 10....

    Hi Folks,
    I have a few Solaris 10 production machines here at work and had a strange thing happen. I added a new route to these machines using the "add route <destination > <gateway>" command and my web applications running in the zones on these machines froze up. The applications that froze had no reason to do this as they have never talked to the machine in this new route. Here is the old route table via netstat -rn:
    Routing Table: IPv4
    Destination Gateway Flags Ref Use Interface
    172.23.248.0 172.23.248.24 U 1 6794 bge1
    204.154.126.0 172.23.248.100 UG 1 0
    204.154.127.0 172.23.248.100 UG 1 0
    204.154.134.0 172.23.248.100 UG 1 0
    204.154.135.0 172.23.248.100 UG 1 0
    204.154.132.0 172.23.248.100 UG 1 0
    204.154.133.0 172.23.248.100 UG 1 0
    204.154.130.0 172.23.248.100 UG 1 0
    204.154.131.0 172.23.248.100 UG 1 0
    204.154.128.0 172.23.248.100 UG 1 0
    204.154.129.0 204.154.129.74 U 1 7980 bge0
    204.68.180.0 172.23.248.100 UG 1 0
    204.68.181.0 172.23.248.100 UG 1 0
    192.168.0.0 172.23.248.100 UG 1 34
    172.28.0.0 172.23.248.100 UG 1 9
    172.29.0.0 172.23.248.100 UG 1 0
    172.30.0.0 172.23.248.100 UG 1 0
    172.31.0.0 172.23.248.100 UG 1 0
    172.24.0.0 172.23.248.100 UG 1 0
    172.25.0.0 172.23.248.100 UG 1 44
    172.26.0.0 172.23.248.100 UG 1 934
    172.27.0.0 172.23.248.100 UG 1 0
    172.20.0.0 172.23.248.100 UG 1 0
    172.21.0.0 172.23.248.100 UG 1 0
    172.22.0.0 172.23.248.100 UG 1 82
    172.23.0.0 172.23.248.100 UG 1 161975
    172.16.0.0 172.23.248.100 UG 1 0
    172.17.0.0 172.23.248.100 UG 1 0
    172.18.0.0 172.23.248.100 UG 1 0
    172.19.0.0 172.23.248.100 UG 1 82
    10.0.0.0 172.23.248.100 UG 1 1766
    224.0.0.0 204.154.129.74 U 1 0 bge0
    default 204.154.129.1 UG 1 8411
    127.0.0.1 127.0.0.1 UH 225713773 lo0
    Here is the route table after I added my one additional route (note the top line):
    Routing Table: IPv4
    Destination Gateway Flags Ref Use Interface
    204.154.129.209 172.23.248.100 UGH 1 5
    172.23.248.0 172.23.248.28 U 1 5757 bge1:3
    204.154.126.0 172.23.248.100 UG 1 0
    204.154.127.0 172.23.248.100 UG 1 0
    204.154.134.0 172.23.248.100 UG 1 0
    204.154.135.0 172.23.248.100 UG 1 0
    204.154.132.0 172.23.248.100 UG 1 0
    204.154.133.0 172.23.248.100 UG 1 0
    204.154.130.0 172.23.248.100 UG 1 0
    204.154.131.0 172.23.248.100 UG 1 0
    204.154.128.0 172.23.248.100 UG 1 0
    204.154.129.0 204.154.129.86 U 1 484 bge0:2
    204.68.180.0 172.23.248.100 UG 1 0
    204.68.181.0 172.23.248.100 UG 1 0
    192.168.0.0 172.23.248.100 UG 1 114
    172.28.0.0 172.23.248.100 UG 1 2
    172.29.0.0 172.23.248.100 UG 1 0
    172.30.0.0 172.23.248.100 UG 1 0
    172.31.0.0 172.23.248.100 UG 1 0
    172.24.0.0 172.23.248.100 UG 1 0
    172.25.0.0 172.23.248.100 UG 1 43
    172.26.0.0 172.23.248.100 UG 1 944
    172.27.0.0 172.23.248.100 UG 1 0
    172.20.0.0 172.23.248.100 UG 1 0
    172.21.0.0 172.23.248.100 UG 1 0
    172.22.0.0 172.23.248.100 UG 1 77
    172.23.0.0 172.23.248.100 UG 1 160823
    172.16.0.0 172.23.248.100 UG 1 0
    172.17.0.0 172.23.248.100 UG 1 0
    172.18.0.0 172.23.248.100 UG 1 0
    172.19.0.0 172.23.248.100 UG 1 0
    10.0.0.0 172.23.248.100 UG 1 183
    224.0.0.0 204.154.129.86 U 1 0 bge0:2
    default 204.154.129.1 UG 1 1850
    127.0.0.1 127.0.0.1 UH 58 225894 lo0:3
    My question is why did my application die and need to be restarted after this one simple route was added? What is the expected behavior in a zone after adding a new route to the root zone?
    Thanks,
    Tom Gellert
    tom.gellert&#64;tellabs.com

    Greg- Dreamweaver CS4/Live View integration with BrowserLab allows you to send interactive states of a local site/design directly to BrowserLab (dynamic data, rollover/mouse interaction states, widget states, et al), and from behind firewalls no less- definitely a scenario we covered.  You can get the extensions (which require Dreamweaver CS4, of course) up on the Labs site: http://labs.adobe.com/technologies/browserlab/

  • Usertable error after adding a udf

    I have a UI add-on that assigns values ​​to a UDT by usertable object of the DI API, the problem is generated after adding a UDF from SAP menu and try to assign a value from the DI. The error is Invalida Field Name
    My question is, is necessary to wait a while until SAP records the new field to be accessible by usertable?
    Any suggestions?
    oUserTable.UserFields.Fields.Item("U_" + colName).Value = respuesta;

    Hi Ricardo,
    As far as I know, you can use this field as soon as it is added to the usertable. But please make sure that this has been added successfully in your table and also make sure that ("U_" + colName ) is the same as it appears in SQL Server. Make sure that you are providing the right field name.
    Hope it helps.
    Thanks & Regards
    Ankit Chauhan

  • A/P Invoice Vendor Ref Number Field updating after adding the Invoice Copy

    Hi All,
                  I am able to change the Vendor Reference number in A/P Invoice Document after adding the Document.  I want to restrict this to happen. Plzz help how to do this????
    Regards,
    Sree.

    1.The Modify Posted A/P Documents authorization refers to some fields only, e.g. the Due Date or Pay to address.
    2. Additional authorization can be defined only for full forms, not for fields.
    3. The SP Joseph suggests will refuse those modifications when the Vendor ref is empty.
    To avoid modifying the Vendor ref you can use this code:
    IF @Object_type = N'18' and @transaction_type = N'U'
    BEGIN
    declare @li int
    set @li=
    (select max(t.LogInstanc)
       from ADOC t
       where t.ObjType=18 and t.DocEntry=@list_of_cols_val_tab_del)
    IF
       (select isnull(t.NumAtCard,'')
        from ADOC t
        where t.ObjType=18 and t.DocEntry=@list_of_cols_val_tab_del
          and t.LogInstanc=@li-1)
    !=(select isnull(t.NumAtCard,'')
       from OPCH t
       where t.DocEntry=@list_of_cols_val_tab_del)
    begin
      Set @error = 10
      Set @error_message = N'Vendor refernce not modifiable !'
    end
    END
    Or if you want to allow modifying an unfilled reference, then this:
    IF @Object_type = N'18' and @transaction_type = N'U'
    BEGIN
    declare @li int
    declare @pref nvarchar(100)
    set @li=
    (select max(t.LogInstanc)
       from ADOC t
       where t.ObjType=18 and t.DocEntry=@list_of_cols_val_tab_del)
    set @pref=
    (select isnull(t.NumAtCard,'')
        from ADOC t
        where t.ObjType=18 and t.DocEntry=@list_of_cols_val_tab_del
          and t.LogInstanc=@li-1)
    If @pref !='' and @pref !=
    (select isnull(t.NumAtCard,'')
       from OPCH t
       where t.DocEntry=@list_of_cols_val_tab_del)
    begin
      Set @error = 10
      Set @error_message = N'Filled vendor refernce not modifiable !'
    end
    END

  • Can't get around this error after adding second dataset...A scope is required for all aggregates used outside of a data region unless the report contains exactly one dataset

    I added a dataset to an existing report and broke an aggregation.  In the old (i.e. single dataset) report, this expression below worked fine.  I wanted to get a distinct count of the vst_ext_id field when my educated field was like "VTE1*"
    = CountDistinct(IIF(Fields!educated.Value like "VTE1*", Fields!vst_ext_id.Value, Nothing))
    After adding a new dataset, this no longer works and I get the error " A scope is required for all aggregates used outside of a data region unless the report contains exactly one dataset".  Having done some research online, I found that I
    needed to specify my dataset explicitly and I thought this new expression might work, but still no success...
    = CountDistinct(IIF(Fields!educated.Value,"DataSet1" like "VTE12*", Fields!vst_ext_id.Value,"DataSet1", Nothing))
    Am I missing something?  Based on online responses, this explicit dataset naming convention seems to help most people, but it isn't working for me. 
    Thanks in advance!
    Brian

    I found the answer.  Apparently, my expression syntax was off.  This expression does the trick...
    = CountDistinct(IIF(Fields!educated.Value like "VTE12*", Fields!vst_ext_id.Value,Nothing),"DataSet1")
    I just happened upon this particular syntax searching online.  I was trying to specify the dataset name after each .value, but I never got that to work.   This is the only time I have found this particular syntax online. 

  • This sign appeared in my account: "Your payment method was declined. Update your biiling info'. After adding new information about my others cards I see the same sign. Can't understand what the problem is and what should I do. Need help!!!

    This sign appeared in my account: "Your payment method was declined. Update your biiling info'. After adding new information about my others cards I see the same sign. Can't understand what the problem is and what should I do. Everything used to be good before.
    Do anyone know what I supposed to do in that situation?
    Really need help!
    Thanks in advance.

    Contact iTunes Customer Service and request assistance
    Use this Link  >  Apple  Support  iTunes Store  Contact

  • WINDOWS 8.1 - System Tools no longer displaying User and Group Settings after adding a new LOCAL user.

    I jumped on my parents computer, which is on a domain.  I added a new local user(with my live.com login) and gave it admin status.  That's when the trouble began.
    The main user profile disappeared.  I used the command prompt fix (see other fixes) to add the missing user back into admin.  I logged back in, and it set up the account for the first time (WTF?).  I cannot access any files from the main account
    (that I logged into just fine before to get this debacle started.)
    When going to Local Computer Management --> System Tools, my users and groups tool is missing.
    I ran lusrmgr.msc only to find out that the most current version of Windows 8.1 and this is what it said "This snapin may not be used with this edition of Windows 8.1.  To manage user accounts for this computer, use the User Accounts tool in the
    Control Panel."   <---- Awesome!  (that was sarcasm.)
    I have spent over two hours in the User Account tool during the course of this problem only to prove that a picture of a computer is more useful that that "tool".  
    To anyone reading this ticket, the best advice I can offer you (as long as its not a crucial machine) is to back up what you can gain access to, format your hard-drive and reinstall windows and start over again.  I wouldn't recommend reinstalling 8.1,
    I would say go back to 7 and wait until 10 comes out.   Windows 8 is the new Vista.  Good luck!

    Hello AhavahOlam,
    I can understand your feelings.
    If my understanding is right, after adding a new local user in domain-joined Windows 8.1, you can’t open the local users and groups.
    Can you still add account by going to Control Panel\User Accounts and Family Safety\User Accounts\Manage Accounts?
    As this computer is domain-based, it is recommended to contact the domain administrator to see if the option is blocked.
    Best regards,
    Fangzhou CHEN
    Fangzhou CHEN
    TechNet Community Support

Maybe you are looking for