Panel doesn't display properly until I resize the frame

Hiya folks,
I'm currently trying to write a simple piece of music notation software. This is my first time using swing beyond a relatively simple JApplet and some dialog stuff. Anywho, I ran into a pretty discouraging issue early on. So far I've got a frame with a menu bar and a toolbar on the bottom border. The toolbar contains a button which should draw a new staff panel containing 11 panels (potentially more) within it, alternating between lines and spaces. Sort of like this:
import javax.swing.*;
import java.awt.*;
public class Staff extends JPanel {
   private static JPanel nsp1,nsp3,nsp5,nsp7,nsp9,nsp11;
   private static JPanel nsp2,nsp4,nsp6,nsp8,nsp10;
   private ImageIcon image= new ImageIcon(this.getClass().getResource( "icons/treble clef.gif"));
    public Staff(){
    setLayout(new GridLayout(11,1));
    add(nsp1= new NoteSpace());
    add(nsp2= new LineSpace());
    add(nsp3= new NoteSpace());
    add(nsp4= new LineSpace());
    add(nsp5= new NoteSpace());
    add(nsp6= new LineSpace());
    add(nsp7= new NoteSpace());
    add(nsp8= new LineSpace());
    add(nsp9= new NoteSpace());
    add(nsp10= new LineSpace());
    add(nsp11= new NoteSpace());
static class NoteSpace extends JPanel{
    public NoteSpace(){
    setPreferredSize(new Dimension(this.getWidth(),2));
static class LineSpace extends JPanel{
      public LineSpace(){
      setPreferredSize(new Dimension(this.getWidth(),1));
      public void paint(Graphics g) {
          super.paint(g);
          g.drawLine(0, (int) super.getHeight()/2, (int)super.getWidth(), (int)super.getHeight()/2);
}Anyway, this panel displays as a tiny box wherein nothing is visible until I resize the frame. Really frustrating. And I have have no idea what the problem might be. Here's the actionlistener:
jbtcleff.addActionListener(new ActionListener (){
        public void actionPerformed (ActionEvent e){
            staff.setBounds(50,panel.getHeight()/2,panel.getWidth()-50,panel.getHeight()/2);
            panel.add(staff);
            staff.repaint();
        });...which is located in a custom jtoolbar class within the Main class, an extension of JFrame:
public class Main extends JFrame{
   JMenuBar jmb=new CustomMenuBar();
   JToolBar jtb= new CustomToolBars("ToolBar");
   static boolean isStaff=false;
   static boolean isNote=false;
   static JPanel panel = new JPanel();
   private static Staff staff= new Staff();
    private static Toolkit toolkit= Toolkit.getDefaultToolkit();
   private static Image image=toolkit.getImage("C:/Users/tim/Documents/NetBeansProjects/ISP/src/MusicGUI/icons/treble clef.jpg");
    private static Cursor noteCursor = toolkit.createCustomCursor(image,new Point(0,0),"Image"); 
   public Main (String m) {   
        super(m);
        setJMenuBar(jmb);    
        getContentPane().add(jtb,BorderLayout.SOUTH);       
        panel.setLayout(new CardLayout(60,60));
        getContentPane().add(panel);
public static void main (String[]args){
        JFrame frame= new Main("Music");
        frame.setSize(800,400);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
        frame.setIconImage(image);
       Sorry for all the code. I'm desperate.
Thanks!

Oh my... have you been through the Swing tutorial?
Let's look at some of your code,
static class NoteSpace extends JPanel{
    public NoteSpace(){
    setPreferredSize(new Dimension(this.getWidth(),2));
static class LineSpace extends JPanel{
      public LineSpace(){
      setPreferredSize(new Dimension(this.getWidth(),1));
      public void paint(Graphics g) {
          super.paint(g);
          g.drawLine(0, (int) super.getHeight()/2, (int)super.getWidth(), (int)super.getHeight()/2);
}Here, NoteSpace and LineSpace are being set to a preferred size of 0x2 pixels, and 0x1 pixels respectfully. If you want them at 0 width, how do you expect them to show? In particular, NoteSpace isn't doing anything special. It's just a panel. Why an inner class? Lastly you should not override paint() for SWING. That's AWT stuff. For Swing, you override paintComponent(Graphics g) .
Then we have this
jbtcleff.addActionListener(new ActionListener (){
        public void actionPerformed (ActionEvent e){
            staff.setBounds(50,panel.getHeight()/2,panel.getWidth()-50,panel.getHeight()/2);
            panel.add(staff);
            staff.repaint();
        });I'm not sure what the variable jbtcleff is, but it seems you are adding your Staff panel to "panel" every time a button is pressed.... why? Why not just add it once (outside the action listener) and be done with it. Your panel object has a CardLayout, so I assume you meant to create a new+ staff panel everytime a button is pressed, and then add it to the card layout panel. Even so, setBounds(...) does not seem pertinant to this goal. (In fact, in most situtations the use of setBounds(...) is the antithesis of using layout managers).
The problem you mentioned though seems to be related to the use of a JPanel (your Staff class) that adds zero-width compontents to a grid array.

Similar Messages

  • Running executable as a service, the front panel doesn't display properly upon the second logon.

    I am running a LabView executable as a service.  When I logon the first time, I see the front panel correctly.  When I logoff, the service still runs properly.  If I logon a second time, the frontpanel never fills in.  (I see the desktop through the front panel).  The service still runs, but when I click on any menu, the computer freezes.  Any suggestions?  (Other than not logging on twice)

    Hi chach,
    I hate to say it, but I'm surprised it even runs once.  If you check out:
    this link
    It says the following:
    "The service must run without a user interface."
    As the article mentions, you could still have a separate front panel that communicates with the service, but the service itself probably doesn't have an accessible front panel.
    Joe Z.

  • Index page CS4 doesn't display properly for google chrome users

    index page CS4/ Dreamweaver doesn't display properly for google chrome users, shows as a blue page /  version of Chrome is 17.0.963.56 m. version of flash is 11.1.102.62.  Operating system is Version 6.1 (Build 7601, Service Pack 1).  Javascript version 1.7.  Quicktime is not installed. 

    www.pianofortemusicschool.com

  • Site doesn't display properly when viewed in Windows 8.1 and IE11

    Web site doesn't display properly when viewed in Windows 8.1 and IE11. Site html and css validates no errors at W3C. Any ideas?

    The following is what I see in IE11 on a Windows 8.1 system, no difference using Firefox, Chrome or Safari on the same system.

  • Album Art doesn't display in all cd in the Zen Visio

    Album art doesn't display in all cd in the Zen Vison M . I have 649 cd and most of them display correct on ZEN Vision M. But some doesn't , I try to delete de Cd and rip it again and add the album art it didn't work for some reason some of the albums does not dipslay. The album art shows in Zen Explorer but not on the Zen vision M. Do you know why. I also try to get the Cover enlarge 200x200 or larger 500x500 but still odesn't work please any help. I had read all the suggestion in the forum also and follow suggestion but it doesn't work.
    Take Care
    AussieDog

    If you select multiple songs and choose Get Info, the Album Art box will always be blank, even if the individual songs each have the same common Art. This is expected behavior.
    Copying the Art directly to the iPod will never work. If your iTunes displays the Art fine, and the nano doesn't, your problem is likely to be a firmware issue with the iPod. I would suggest performing a "restore" and then try again. Otherwise, if issues remain, reinstall iTunes if more than one XP user is affected.

  • Option Click on the Volume menubar icon doesn't display ALL airplay devices, just the last one used

    Option Click on the Volume menubar icon doesn't display ALL airplay devices, just the last one used. I've seen other peoples display all their devices. Why can't I?

    I've discovered that those screenshots where you see more than one speaker listed in the menubar icon are actually bluetooth devices, not airplay. When you check the shot of the system preferences pane and see them all listed there too, the Type says Bluetooth. Not sure why bluetooth gets them all listed and apple's own airplay standard does not. Hope a developer writes a mac app to do it!

  • When I open my email in the text box it doesn't show anything until i hit the forward button.  Can anyone help?

    When I open my email in the text box it doesn't show anything until i hit the forward button.  Can anyone help?

    See if any of the following help.
    Try turning the account off and on : Settings > Mail, Contacts, Calendars , then tap the account on the right, slide Mail to 'off', exit settings and go back into the Mail app, and then go back to Settings and slide Mail back to 'on'
    If that doesn't work then try closing the Mail app completely : from the home screen (i.e. not with the Mail app 'open' on-screen) double-click the home button to bring up the taskbar, then press and hold any of the apps on the taskbar for a couple of seconds or so until they start shaking, then press the '-' in the top left of the Mail app to close it, and touch any part of the screen above the taskbar so as to stop the shaking and close the taskbar.
    Also do a reset : press and hold both the sleep and home buttons for about 10 to 15 seconds (ignore the red slider), after which the Apple logo should appear - you won't lose any content, it's the iPad equivalent of a reboot.

  • Problem with dragged component after resizing the frame

    My application is simple: I am displaying an image on a panel inside a frame (JFrame). I am able to drag the image inside the panel. My problem is that, after dragging the image around, if I am resizing the frame, the image goes back to its original position.
    Does anyone know a workaround?
    I have been using the sample provided by noah in his answer (reply no. 3) to a previous question on this forum: http://forum.java.sun.com/thread.jsp?forum=57&thread=126148
    Thank you!

    Chek out the visibility of your components. Some operations may render them invisible. Use the setVisible( boolean ) to make them visible.

  • E61i internet browser doesn't display properly

    Hello,
    I never had any problems browsing the internet on my E61i. My Nokia is always switched on, but today I had to switch it off for a while. After switching in on again, I wanted to use the internet on it. The strange thing was that it wouldn't display any web page properly any more. Pages look messy, like the web browser doesn't how to handle HTML etc. and display it properly.
    I often visit web pages not specially made for PDA's, so when visiting these I had to scroll horizontally. That was ok. But now when visiting these pages I cannot scroll horizontally any more; the browser puts all web page contents beneath each other, if you know what I mean. Now I can only scroll vertically.
    The conclusion is that many web pages I used to visit have now become useless since the E61i web browser doesn't display them any more as they used to be displayed, the pages used to look like as if you visited them from a PC, but not any more.
    Does anybody have a clue?

    It sounds like a cache issue. When you view the page, that
    page is loaded into your (or your client's) browser's cache memory.
    This is done so that when you return to that page it will load
    faster (since it is already loaded into memory).
    This will only happen if a person has been to the page
    recently. There is a limit on the amount of information your
    browser will store in cache memory. The more you surf, the more
    likely it is that the page will be replaced in the cache memory
    with some other information.
    You (and your client) can, depending on what browser you are
    using, set your preferences so that all web pages will be
    completely reloaded every time you visit them. In IE 6 for Win:
    Tools>Internet Options>Settings> Select 'Every visit to
    the page'. You can also set your cache to be the minimum amount of
    space alotted. Note: This doesn't really work very well in IE 6 for
    WIN. I use firefox for reviewing changes because I have found IE 6
    is completely unreliable for viewing the latest.
    Most other browsers will allow you to hold down Shift and hit
    'refresh' to throw out the cache for that page and view the latest.
    As far as I know this is standard operating procedure for proofing
    new pages.
    If there is a coding technique to force a browser to use only
    the latest information, I don't know what it is.
    Good luck.

  • Paypal express checkout doesn't display properly - Firefox 33.0.3

    Paypal express checkout doesn't appear to be displaying properly in firefox (link to screenshot below). I've tried it with Chrome & IE and it works fine, so can only assume this is a firefox bug.
    Screenshot:
    http://voodoo-london.com/ss.png
    I've tried everything in regards to clearing cookies & cache but still no luck.
    Can anyone offer any explanation or resolution for this?

    Separate Issue; Update your
    Flash Player '''v15.0.0.189 http://get.adobe.com/flashplayer/'''
    Please flag your last post as '''Solved Problem''' so other will know.

  • Externally loaded swf in second window doesn't display properly?

    I have a bitmap based flash game (bitmapdata generated screen) that I'm trying to load in to a secondary nativewindow generated from a main flash (not AJAX/HTML)  based AIR app that's a graphical menu.  I.E. you click on a selection in the menu, and it pops open a secondary nativewindow with the flash game running in it.  The problem is, the game itself gets mangled in the secondary window when it loads in.  Keyboard input goes away, the bitmap doesn't draw properly (it streaks like its not drawing the background image each frame), most of the game objects its supposed to draw in to the bitmap are missing, etc. 
    When I make the game itself in to its own AIR app and run it direct, it works just fine.  So I'm puzzled.  Is there some kind of special coding considerations in the as3 side that I'm missing with the original game?  I.E. if a flash based AIR app launches another nativewindow and loads a swf in to that, does it share some kind of variable set, display list, etc. with the calling window?  Something else?  Any help would be appreciated.

    There are a few differences between (A.) letting the AIR runtime load content into the initial window and (B.) loading content into a new NativeWindow.
    1. In case A, the stage property is available in the class constructor for the main sprite. In case B, this is not the case. You may have to use an ADDED_TO_STAGE event handler to do some class initialization.
    2. In case A, the initial scale is based on the metadata present in the SWF -- this results in the behavior you would expect. In case B, there is no SWF to base the scale on when the window is created, so a default scale is used -- this is rarely results in behavior you would expect (unless the window happens to be created with a size of 72x72 pixels).
    If you aren't setting the stage to noScale, then this could account for some of the visual issues. (See http://www.adobe.com/devnet/air/flex/quickstart/launching_windows.html for an explanation of the scaling issues.) The easiest thing to do is to set the Stage scaleMode to noScale and the align property to the top left setting. I'm guessing your drawing code isn't expecting the scaling so things are getting put in the wrong place.
    3. In case A, the content is automatically put in the application sandbox. In case B, it depends on the URL.
    As for the Keyboard input, this may depend on how you are loading the SWF and from where. This could be related to #3 above, although I would expect to see security errors. How are you adding your keyboard event handlers?

  • Navigator Window Doesn't display properly

    Hello,
    Suddenly the Navigator Window on the Left of JDeveloper doesn't show properly.Usually the window has 2 subwindows : the top which displays WorkSPace-Projects-classes and bottom which shows the members and methods for each class. Now my top window doesn't show at all. It is like it has been minimized and i cannot restore it. The bottom window occupies all the space.
    When i place the cursor on top of the upper border of the bottom window (just under the green X icon) the cursor changes to a shape that shows that there is another window there but i cannot drag the border down and display again the top navigator window.
    What can i do about that ? ?

    I have seen this problem before but I have not been able to reproduce it.
    The workaround is to:
    - Open the 'Welcome' workspace (Help|Welcome Workspace)
    - Close JDeveloper
    - Launch JDeveloper
    - Open your workspace
    Hope this helps.
    Please let us know if you are still running into problems.
    Regards,
    Arun

  • SimpleChat doesn't display properly for spark on mobile

    I'm using the latest LCCS Spark Beta version. The SimpleChat displays RAW html instead of the styled text, plus it doesn't scroll properly. This problem was posted a few months back but is yet to be resolved. Looking at the LCCS sdk source code, the problem seems obvious: SimpleChat uses the class RichTextArea which the lccs team has created. That class checks to see if "textFlow" exists. If it doesn't as in the case of mobile it just assigns the raw html to the text field which is obviously unacceptable since the user will end up seeing raw html instead of styled text. Below is the problematic code in the lccs RichTextArea class. Is LCCS team supporting mobile devices?
                   if (textFlow)
                        textFlow = TextConverter.importToFlow(str, TextConverter.TEXT_FIELD_HTML_FORMAT);
                    else  {
                        //StyleableTextField(textDisplay).htmlText = str;
                        textDisplay.text = str;

    www.pianofortemusicschool.com

  • CSS - main content h1 and p text doesn't display properly

    Hi all,
    I know this is something really simple, but I just can't seem to get it right.  The h1 and the p text in the main content should have left and right padding to display properly (i.e. space on either side so it's not squished against the Accordion Spry), but it doesn't work.  It shows correctly in DW, but not online.  I'm just learning CSS so sorry for the ignorance!  I've tried everything I know and can't seem to get it right.  I would appreciate ANY help at all.
    http://www.TailgatorsHockey.com/news.html
    Attached is the .css file...
    Thanks so much!

    The padding and margin are certainly showing in the browser for the h1 tag but you have no padding or margin declared in your css styles for the paragraph tag in the 'main-content' <div>
    Add ths to your css styles:
    #main-content p {
    padding: 0 25px 0 25px; /*top/right/bottom/left*/
    margin-left: 10px;

  • Quicklook - DNG previews are not honored. Doesn't display properly.

    10.5.1, Aperture 1.5.6
    Is there workaround to get the Finder's Cover Flow or Quicklook views to honor and display JPEG previews from DNG images?
    As it is now, the Finder displays only a preview from the original, untouched DNG image.
    To recreate this, open a DMG image in Aperture. Make image adjustments. Crop the photo. Close out of Aperture, and view the image in the Finder using Cover Flow and Quicklook. The image will appear as if it was never adjusted.
    (The sole exception seems to be image rotation. The Finder preview show the image properly rotated.)

    There are a few differences between (A.) letting the AIR runtime load content into the initial window and (B.) loading content into a new NativeWindow.
    1. In case A, the stage property is available in the class constructor for the main sprite. In case B, this is not the case. You may have to use an ADDED_TO_STAGE event handler to do some class initialization.
    2. In case A, the initial scale is based on the metadata present in the SWF -- this results in the behavior you would expect. In case B, there is no SWF to base the scale on when the window is created, so a default scale is used -- this is rarely results in behavior you would expect (unless the window happens to be created with a size of 72x72 pixels).
    If you aren't setting the stage to noScale, then this could account for some of the visual issues. (See http://www.adobe.com/devnet/air/flex/quickstart/launching_windows.html for an explanation of the scaling issues.) The easiest thing to do is to set the Stage scaleMode to noScale and the align property to the top left setting. I'm guessing your drawing code isn't expecting the scaling so things are getting put in the wrong place.
    3. In case A, the content is automatically put in the application sandbox. In case B, it depends on the URL.
    As for the Keyboard input, this may depend on how you are loading the SWF and from where. This could be related to #3 above, although I would expect to see security errors. How are you adding your keyboard event handlers?

Maybe you are looking for

  • WLS 6.1 SP4: bug in ExecuteThread's contextClassLoader behavior?

    Platform: WebLogic Server 6.1 SP4, JDK 1.3.1_06, Windows When creating a new thread from a serlvet with a current thread of type "weblogic.kernel.ExecuteThread", the contextClassLoader of the new thread is set incorrectly. The contextClassLoader of t

  • How can I find when I loaded Maverick? I want to uninstall.

    How can I find when I loaded Maverick?  I want to uninstall it, but I want to go back to before I installed it for Time Machine.

  • Snow Leopard client for NetRestore image not being recognized in Mountain Lion Server

    I target firewired a MacBook Pro running Snow Leopard and ran System Imaging Utility and the machine does not show up as an option. Does Mountain Lion Server support Snow Leopard NetRestore images or am I doing something wrong?

  • Airport extreme not compatible with xbox live?

    Hello, Ive had this problem for a long while now and are getting desperate. Basically when i go on xbox live the connection is really really bad. It's not all the time, rarely it will work fine but most of the time the connection is awful. I know the

  • Can't sync iPhoto content

    I can access my shared iTunes library remotely, and in iTunes/AppleTV/iPhoto, I have selected libraries to sync. But no photos are on the ATV. I'd like to use my pics as a screensaver, but.... It seems like I've set this up right. Ideas? PROBLEM SOLV