Why won't JPanel show up in an external JFrame?

My code generates a graph and displays it in a JPanel.
If the class extends JFrame, the output looks exactly as it should. The problem is that I need to extend it as a JPanel so that I can imbed it in another GUI. When I modify the code so that it is a JPanel, the graph does not show up at all (except a tiny little smudge).
What am I missing? Here is a trimmed down version:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.util.*;
* @author Rob Kallman <[email protected]>
public class GraphSSCCE extends JPanel {
     protected JPanel mainPanel;
     protected JPanel graphPanel;
     protected final int FRAME_PANEL_WIDTH = 950;
     protected final int FRAME_PANEL_HEIGHT = 400;     
     protected final int GRAPH_PANEL_WIDTH = 950;
     protected final int GRAPH_PANEL_HEIGHT = 400;
     protected final int NODE_COUNT = 3;
     protected final int node_d = 30;
     protected int centerX = GRAPH_PANEL_WIDTH/2;
     protected int centerY = GRAPH_PANEL_HEIGHT/2;
     protected java.util.List<Node> nodes = new ArrayList<Node>(NODE_COUNT);
     public GraphSSCCE() {
          //super("Graph Redux");
          this.setSize(FRAME_PANEL_WIDTH,FRAME_PANEL_HEIGHT);
          //this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          mainPanel = new Graph();
          this.setBackground(Color.WHITE);
          this.add(mainPanel);
     public static void main(String args[]) {
          JFrame frame = new JFrame("Graph Test");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          GraphSSCCE gr = new GraphSSCCE();
          frame.setSize(gr.getSize());
          frame.add(gr);
          frame.setVisible(true);
@SuppressWarnings("serial")
class Graph extends JPanel {
     public Graph() {
          super();
          graphPanel = new JPanel();
          graphPanel.setBackground(Color.WHITE);
          graphPanel.setSize(GRAPH_PANEL_WIDTH, GRAPH_PANEL_HEIGHT);
          repaint();
     public void paint(Graphics g) {
          super.paint(g);
          int graphW = graphPanel.getWidth() - 100;
          int graphH = graphPanel.getHeight() - 100;
          //Draw Root node
          Node root = new Node(0, (graphPanel.getWidth() - 100)/4, graphH/2 + 20, node_d);
          g.setColor(Color.BLACK);
          g.fillOval(root.x-2, root.y-2, root.d + 4, root.d + 4);
          g.setColor(Color.RED);
          g.fillOval(root.x, root.y, root.d , root.d);
          //Draw site nodes
          for(int i = 0; i < NODE_COUNT; i++) {
               double nc = NODE_COUNT;
               double frac = i/(nc-1);
               Node node = new Node(i, 3*(graphW)/4, (int)(frac * graphH) + 20 + (int)frac, node_d);
               nodes.add(i, node);  // An ArrayList that contains all of the Node objects.
          // Populate network with edges from root to site     
               for(Node noodle : nodes) {
                    g.setColor(Color.BLACK);
                    g.drawLine(root.x + root.d/2, root.y + root.d/2, noodle.x + noodle.d/2, noodle.y + noodle.d/2);
                    g.setColor(Color.BLACK);
                    g.fillOval(noodle.x - 2, noodle.y - 2, noodle.d + 4, noodle.d + 4);
                    g.setColor(Color.RED);
                    g.fillOval(noodle.x, noodle.y, noodle.d, noodle.d);
               g.setColor(Color.BLACK);
               g.fillOval(root.x - 2, root.y - 2, root.d + 4, root.d + 4);
               g.setColor(Color.RED);  // Root
               g.fillOval(root.x, root.y, root.d, root.d);
class Node {
     protected int d;
     protected int x;
     protected int y;
     protected int node_id;
     public Node(int id, int x, int y, int d) {
          this.node_id = id;
          this.d = d;
          this.x = x;
          this.y = y;
}

Welcome to the Sun forums.
>
What am I missing? ...>That code was doing some odd things. Once I'd trimmed it down far enough to get it working, I'd made a number of undocumented changes. Have a look over this, and see if it get you back on track.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.util.*;
* @author Rob Kallman <[email protected]>
public class GraphSSCCE extends JPanel {
     public static void main(String args[]) {
          JFrame frame = new JFrame("Graph Test");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          Graph gr = new Graph();
          JPanel mainPanel = new JPanel(new BorderLayout());
          mainPanel.add(gr, BorderLayout.CENTER);
          frame.setContentPane(mainPanel);
          frame.pack();
          frame.setSize(gr.getSize());
          frame.setVisible(true);
@SuppressWarnings("serial")
class Graph extends JPanel {
     protected final int FRAME_PANEL_WIDTH = 950;
     protected final int FRAME_PANEL_HEIGHT = 400;
     protected final int GRAPH_PANEL_WIDTH = 950;
     protected final int GRAPH_PANEL_HEIGHT = 400;
     protected final int NODE_COUNT = 3;
     protected final int node_d = 30;
     protected int centerX = GRAPH_PANEL_WIDTH/2;
     protected int centerY = GRAPH_PANEL_HEIGHT/2;
     protected java.util.List<Node> nodes = new ArrayList<Node>(NODE_COUNT);
     public Graph() {
          super();
          setBackground(Color.WHITE);
          repaint();
     public Dimension getPreferredSize() {
          return new Dimension(GRAPH_PANEL_WIDTH,GRAPH_PANEL_HEIGHT);
     /** Do not override paint() in a Swing component! */
     public void paintComponent(Graphics g) {
          super.paintComponent(g);
          g.setColor(getBackground());
          g.fillRect(0,0,getWidth(),getHeight());
          int graphW = getWidth() - 100;
          int graphH = getHeight() - 100;
          //Draw Root node
          Node root = new Node(0, (getWidth() - 100)/4, graphH/2 + 20, node_d);
          g.setColor(Color.BLACK);
          g.fillOval(root.x-2, root.y-2, root.d + 4, root.d + 4);
          g.setColor(Color.RED);
          g.fillOval(root.x, root.y, root.d , root.d);
          //Draw site nodes
          for(int i = 0; i < NODE_COUNT; i++) {
               double nc = NODE_COUNT;
               double frac = i/(nc-1);
               Node node = new Node(i, 3*(graphW)/4, (int)(frac * graphH) + 20 + (int)frac, node_d);
               nodes.add(i, node);  // An ArrayList that contains all of the Node objects.
          // Populate network with edges from root to site
               for(Node noodle : nodes) {
                    g.setColor(Color.BLACK);
                    g.drawLine(root.x + root.d/2, root.y + root.d/2, noodle.x + noodle.d/2, noodle.y + noodle.d/2);
                    g.setColor(Color.BLACK);
                    g.fillOval(noodle.x - 2, noodle.y - 2, noodle.d + 4, noodle.d + 4);
                    g.setColor(Color.RED);
                    g.fillOval(noodle.x, noodle.y, noodle.d, noodle.d);
               g.setColor(Color.BLACK);
               g.fillOval(root.x - 2, root.y - 2, root.d + 4, root.d + 4);
               g.setColor(Color.RED);  // Root
               g.fillOval(root.x, root.y, root.d, root.d);
class Node {
     protected int d;
     protected int x;
     protected int y;
     protected int node_id;
     public Node(int id, int x, int y, int d) {
          this.node_id = id;
          this.d = d;
          this.x = x;
          this.y = y;
}

Similar Messages

  • HT3669 Now that the driver update allows my HP printer to scan, why won't it show up in Image Capture?

    Now  that the driver update allows my HP all-in-one to scan, why won't it show up in Image Capture?

    According to IC's help:
    If you can’t see your scanner in the list, refer to the documentation that came with your scanner to see how to scan images.
    Alternatively, quit IC, reset your AIO in Print&Fax prefPane, relaunch IC, and see if that lists it.

  • Why won't airdrop show up on my control center on my iPad? Also i can't get my pictures to sync from my phone to iPad through sharing.

    why won't airdrop show up on my control center on my iPad? Also i can't get my pictures to sync from my phone to iPad through sharing.

    AirDrop is not available on an iPad 2 or on an iPhone 4S.
    To share content with AirDrop, both users need one of the following devices using iOS 7:
    iPhone 5 or later
    iPad (4th generation)
    iPad mini
    iPod touch (5th generation)
    http://support.apple.com/kb/ht5887
    As to your photos, what sharing are you attempting?  Did you enable Photo Stream?
    http://support.apple.com/kb/ht4486

  • Why won't Apple show in my Common files?

    Why won't Apple show up in my common files when I try to update my Iphone

    I assume Canon 70D came after Lr4 was no longer being fitted with new camera support (i.e. when Lr5 was released).
    (feel free to double-check that assumption - if wrong, then forget the rest of this post..).
    Remedies:
    * upgrade to Lr5, or
    * convert to DNG (using free Adobe Converter).
    ~R.

  • Why won't google work? whenever i try to go to google it just saya 404 Not Found. Also why won't captcha show up. when i have to type in a captcha to show i'm not a robot the words won't show up.

    why won't google work? whenever i try to go to google it just saya 404 Not Found. Also why won't captcha show up. when i have to type in a captcha to show i'm not a robot the words won't show up

    Hey briannagrace96,
    Welcome to Apple Support Communities! I'd check out the following article, it looks like it applies to your situation:
    iPod: Appears in Windows but not in iTunes
    http://support.apple.com/kb/ts1363
    You'll want to go through the following troubleshooting steps, and for more detail on each step follow the link to the article above:
    Try the iPod troubleshooting assistant:
    If you have not already done so, try the steps in the iPod Troubleshooting Assistant (choose your iPod model from the list).
    If the issue remains after following your iPod's troubleshooting assistant, follow the steps below to continue troubleshooting your issue.
    Restart the iPod Service
    Restart the Apple Mobile Device Service
    Empty your Temp directory and restart
    Verify that the Apple Mobile Device USB Driver is installed
    Change your iPod's drive letter
    Remove and reinstall iTunes
    Disable conflicting System Services and Startup Items
    Update, Reconfigure, Disable, or Remove Security Software
    Deleting damaged or incorrect registry keys
    Take care,
    David

  • TS1424 why won't my show copy to my ipod

    my show won't copy and i done everything the people tell me to do

    You said "Then when you run an update it just goes back as it was. Any ideas?" What does this mean?
    You can only sync apps from the one syncing computer you can have.
    Did you setup the iPod via wifi?
    Have you tried restoring from backup on this computer/iTunes library?
    The app assume the apps are compatible with your iPod

  • Why won't images show in Reflow?

    None of the images from my Photoshop file display when i open the file in Reflow. I put the .PNG or .JPG suffixs on the end of every image layer, yet none show in Reflow, just a broken link icon. I checked the images in the Reflow assets folder, they are all there, so i cant understand why they arent displaying in Reflow. Thanks in advance. M

    Sorted it, thanks

  • Why won't google show images just text since loading new software

    I just loaded new software for ipad but now google images just shows text
    Any ideas

    Hello Burgess944,
    The following article provides troubleshooting steps that can help resolved most issues with apps on your iPad.
    iOS: An app you installed unexpectedly quits, stops responding, or won’t open
    http://support.apple.com/kb/TS1702
    Cheers,
    Allen

  • Disk could not be read from or written to? Why won't my show download?

    Everytime I try to download the latest episode of Grey's Anatomy, the show starts to download and gets toward the end, but then says Error: Disk could not be read from or written to. Other short movies and music have downloaded fine; it's just this one episode. Am I doing something wrong or is it the store?
    Thanks for you help!
    Anna

    also worth noting I deleted a load of stuff on my mac to make space but no luck

  • Why won't iPad1 show up as a Device in iTunes when the iPad is Wi-Fi and powered up?

    iPad1 is properly designated to be Wi-Fi sync'd to the Windows 7 64.
    iPad correctly shows Device in iTunes; and correctly sync's in iTunes when tethered to computer via USB.
    No Device listed  in iTunes when iPad is on and powered by 10w power cube.
    Network connects.
    iCloud backup works when Wi-Fi.
    iPad USED to be visible to iTunes when on and powered and on Wi-Fi.
    Some anti-miracle occured.
    Need exorcist.

    Thank you for your reply; however I don't believe that your advice fits my circumstance - in that my device (in this case, the iPad) DID show up as a Device in iTunes last week - when connected via Wi-Fi (that is, powered up and on the home network and with iTunes open in the Windows 7 computer).
    I was then able to communicate (read: sync) between the iPad and the computer NOT using the USB cable-connect to the computer - merely via Wi-Fi.
    I can not repeat that miracle this week (meaning, that I must hook up the iPad1 to the computer via the USB cable, where it does register as a Device in iTunes - and it does go thru the 6 steps of sync.
    Did I grossly missinterpret your instructions?
    Thank you, in advance, for any additional assistance.

  • Why won't Illustrator show pms color accurately?

    If I draw a box in illustrator and fill it with pms 180 it's bright orange. When I do the same thing in photoshop it's red (which is much closer to the actual color). I've synched all of my color settings in bridge but that doesn't make any difference. When I copy the image from illustrator and paste it into photoshop it's still orange. And when I save it as a pdf or export it as a jpeg, it's still orange. I can make it look red in illustrator by switching to overprint preview, but that doesn't do my any good. When I send this file to my client. They keep asking why it's orange and not red!!!

    Get your color management in sync between apps using bridge >> edit > creative suite color settings.
    Make sure both apps are in same color space (cmyk or rgb)
    Below is screenshot of a placed .psd in illustrator against a vector rectangle both filled with pms 180
    If your mintor is color calibrated, then my screenshto should look close to what it shodul be on your monitor. Will never be perfect, especially with some colors  (flourescent, metallic)

  • HT5622 Why won't it show the state I'm in for the billing information?

    I'm trying to input my billing information but it's not showing my state. What do I do?

    From Demo:
    If you are getting the blank app update screen, and, many people are having this problem over the last several of days:
    According to Fly150 in another discussion, this will work.
    If you want to update the Apps while waiting for Apple to fix Updates:
    1. Go to App Store
    2. Select Purchased
    3. Select All
    4. Scroll down to find the Apps showing update
    5. Select update on the Apps
    This should update the Apps and get rid of the update count in App Store. Apple needs to fix this. It is a workaround only until then.
    Or try this from Apple:
    I understand that your App Store does not show your app updates. Please follow the steps below to help resolve the issue.
    1. Close All Apps on iPad: http://support.apple.com/kb/ht5137
    2. Sign out of iTunes & App Stores: Settings > iTunes & App Stores > Tap AppleID > Sign out
    3. Reset All Settings: Settings > General > Reset > Reset All Settings
    4. Reboot iPad
    5. Sign back into iTunes and App Stores: Settings > iTunes & App Stores > Sign In with AppleID
    Thank you for being an iTunes store customer. Apple appreciates your business.

  • Why won't Safari show Skydrive pdf files under ios 6

    Like a number of others, I posted on the MS Skydrive forum
    viz: I notice that when I try to access the pdf files on my skydrive, there will be an error message written as follows "Unable to display "my_pdf_file_name" in this browser. Check your browser settings to see if you have a PDF plugin installed and enabled. If you have a PDF viewing application, you can download the file and open it from your computer" However, when i click download, nothing happens.
      I have to share a set of documents via Skydrive and the email link I send opens safari (Ios 6) and bingo! The pdf files cannot be opened and nor do they download.
    The response form Microsoft is:
    After testing it has been found that the cause of this is the way Safari handles 3rd party cookies. This is not an issue with SkyDrive but instead Safari iteslf. Other websites have the PDF as an attachment allowing it to just open, where SkyDrive has security that must be passed. Safari is not allowing this cookie/script to run and preventing. So, this will need to be an Apple resolution.
    Can someone at Apple resolve this or come up with a sensible workaround please?
    Pete

    Apple is not here, this is a user to user forum.
    To contact apple and suggest the change you can go here:
    http://www.apple.com/feedback/
    Just select your device and fill in the form.
    As to how you can get PDFs from skydrive Why not use the Skydrive app?
    https://itunes.apple.com/us/app/skydrive/id477537958?mt=8
    You can open them natively in the app or after they've opened save them into iBooks, or any other App that may be able to open them.

  • Why won't iMovie show pictures in the trailers? And other problems...

    When I try to insert pictures into my imovie trailer it lets me but it becomes black during the time it's supposed to show. Videos are fine though. Also, whenever I create a trailer, the wording disappears before you can even read it. any ideas? It is so annoying and I would like to get it fixed ASAP. Thanks guys.

    Hey I had the same problem for days now. I tried everything including resetting my phone even my wi fi DNS and nothing seems to work. I've been searching and searching for days and nothing seems to work, and FINALLY I decided to back up all my videos and pictures onto my computer then rebooting my iphone completely. Here are the steps if you want your iphone to work again. First connect your phone to your computer open itunes and back up everything from your iphone to your computer it will take a couple of minutes. After that is done just go back to your phone to settings/ general/ reset/ ERASE ALL CONTENT AND SETTINGS and just click on continue your phone will shut off once it turns back on just follow the instructions it also has you either create an icloud name or use your old one, once you log onto your iclouds and set up everything go to settings then messages and sign in and wah lah it works! I was really excited I've been a little annoyed with the whole stituation and now I'm just happy it's fixed. Hope this works!!

  • Why won't this show (same) four pages in the Adobe Reader?

    %PDF-1.6
    3 0 obj
    <</Type /Font /BaseFont /Times-Italic /Subtype /Type1 >>
    endobj
    6 0 obj
    <</Length 158 >>
    stream
    1 0 0 1 50 200 cm /X1 Do
    1 0 0 1 0   200 cm /X1 Do
    1 0 0 1 0   200 cm /X1 Do
    1 0 0 1 200 -400 cm /X1 Do
    1 0 0 1 0 200 cm /X1 Do
    1 0 0 1 0 200 cm /X1 Do
    endstream
    endobj
    4 0 obj
    <</Type /XObject /Subtype /Form /BBox [0 0 1000 1000] /Resources <</Font <</F1 3 0 R>> >>
    /Length 77 >>
    stream
    BT /F1 18 Tf 0 0 Td (18 Point) Tj ET
    BT /F1 25 Tf 0 50 Td (25 Point) Tj ET
    endstream
    endobj
    5 0 obj
    <</Type /Page /Parent 2 0 R /Contents 6 0 R /MediaBox [0 0 595.27 841.88] /UserUnit 0.5 /Resources <</XObject <</X1 4 0 R>> >>
    >>
    endobj
    2 0 obj
    <</Type /Pages /Kids [5 0 R 5 0 R 5 0 R 5 0 R ] /Count 4 >>
    endobj
    1 0 obj
    <</Type /Catalog /Pages 2 0 R >>
    endobj
    xref
    0 7
    0000000000 65535 f
    0000000745 00000 n
    0000000667 00000 n
    0000000010 00000 n
    0000000297 00000 n
    0000000517 00000 n
    0000000085 00000 n
    trailer
    <<
    /Root 1 0 R
    /Size 7
    >>
    startxref
    796
    %%EOF
    Works OK with Chrome's reader......

    1. It may surprise you, but more than 50% of the problems which people ask about with PDF generators turn out to be related to the exact byte layout, and disappear (or get worse) with copy/paste. People with tools for PDF examination like to be able to use them and know they are working on the exact/same file.
    "But why can it not do that."
    Because the question is unanswerable. Imagine an API call
    PageObjectGetPageNumber().
    Given object 5 0 R and asking for the page number, what is the correct answer - 1, 2, 3, or 4? This is of more than academic interest. For example, the page object might be the destination of a link, and an interactive viewer needs to know which page to navigate to. So, while a simple PDF viewer could display it, many things might not work.
    ISO 32000-1 doesn't forbid it. But there isn't much mileage in taking the high ground and saying that one is making good files but Acrobat isn't compliant.

Maybe you are looking for

  • Usb ports are not working in windows 7 (64bits)

    hello  recently installed windows 7 on my laptop 15-n203tx  problem is my usb ports are working great in pre installed win 8.1 but now in win 7 just one port is working and it is usb port 2.0 and other two are 3.0 and not workng plz help me to fix th

  • h1 The Use Of Header Tags

    I'm becoming more aware of the importance of using header tags to help the visually impaired navigate your site.  Obviously the main header should be wrapped in an <h1> tag, however after that does it flow from <h1> all the way to <h6>, and what if y

  • A simple BADI implementation - very urgent

    Hi,   I am new to ABAP. I need a small piece of coding. I am implementing a BADI. There is a table which has 3 fields (MATID, LOCID, STATUS and PLANNING_DATE). For each MATID (material ID), there are many LOCID (Location ID) available. My BADI has to

  • Trying to write an Automator program to find files with same time created and change file names to matching source folder names

    I am failrly green when it comes to automator. I am trying to write an Automator program: Not sure where to post this trying to write an Automator program to find files and alter their names I have a source folder with correct named master files in i

  • 3 Problems (IDE, Corrupt files, SATA)

    1) i do not want to use either sata or ide raid. i have 2 sata hdd and 5 ide devices (3x hdd, 2x cdroms) is it possible to connect all of them onto the mainboard so that all of them will work independantly (no raid). Or do i need an add-on ide contro