Can I make a class holding multiple GUI components and make it visible?

I am implementing an MDI where the different JInternalFrames are filled with a JPanel with components. Since the contents of my screen is dynamically generated, each screen can have multiple Jlabels, JTextFields, etc.
So I thought, I make a class containing the representation of one row of GUI components on my screen, which is: one JLAbel and 4 JTextFields.
Here is the code which adds the components to the panel:
// create panel
JPanel qpanel = new JPanel();
qpanel.setLayout(new BoxLayout(qpanel, BoxLayout.Y_AXIS));
qpanel.add(Box.createVerticalStrut(5));
//add rows to panel
for( int i = 0; i < nrRows; i++)
// qpanel.add(new JLabel("Hello how are you"));
qpanel.add(new ProcessRow("hello","how","are","you"));
// add panel to scrollpanel
this.getViewport().add(qpanel);
Here is the ProcessRow class:
public class ProcessRow extends JComponent
public JLabel rowLabel = null;
public JTextField myCost = null;
public JTextField saratogaCost = null;
public JTextField sapCost = null;
public JTextField totalCost = null;
public ProcessRow() {
super();
public ProcessRow(String LABEL,
String DEFAULTCOST,
String SARATOGACOST,
String SAPCOST){
super();
JLabel rowLabel = new JLabel(LABEL);
JTextField myCost = new JTextField(DEFAULTCOST, 6);
JTextField saratogaCost = new JTextField(SARATOGACOST, 6);
JTextField sapCost = new JTextField(SAPCOST, 6);
JTextField totalCost = new JTextField(6);
If I add the label "Hello how are you" directly to the panel, it shows fine but if I use my ProcessRow class, nothing shows.
How can I make it visible and if not,
how can I dynamically keep adding all these GUI components without loosing control over the components.
Thanks,
Johnny

Modify your ProcessRow:
(1) First extends JPanel ( Container, not Component)
(2) Add Label and TextField to the container
public class ProcessRow extends JPanel
public JLabel rowLabel = null;
public JTextField myCost = null;
public JTextField saratogaCost = null;
public JTextField sapCost = null;
public JTextField totalCost = null;
public ProcessRow() {
super();
public ProcessRow(String LABEL,
String DEFAULTCOST,
String SARATOGACOST,
String SAPCOST){
super();
JLabel rowLabel = new JLabel(LABEL);
JTextField myCost = new JTextField(DEFAULTCOST, 6);
JTextField saratogaCost = new JTextField(SARATOGACOST, 6);
JTextField sapCost = new JTextField(SAPCOST, 6);
JTextField totalCost = new JTextField(6);
// add everything to the container.
add(rowLabel);
add(myCost);
add(sapCost);
add(totalCost);
}

Similar Messages

  • How can I get an excel spreadsheet onto the iPad and make changes to it?  I need this for a meeting this afternoon.

    How can I get an excel spreadsheet onto the iPad and make changes to it during my meeting this afternoon?

    I just bought splashtop, you have to have your home computer online,and download the pc version.  I have used it ot watch movies and to "go to work" on my ipad.  It controls the desktop through the ipad.  Whiteboard by splashtop does that and more and is on sale.  The education director at the hospital I work at is using that one.
    Splashtop 4.99 remote desktop(or laptop) control. Whiteboard 9.99 is remote control and more 9.99
    Julie

  • HT5071 Can I publish my work produced with iBooks Author and make it available (free of charge) for my students only?

    Can I publish my work produced with iBooks Author and make it available (free of charge) for my students only?

    Yes. Put it on your own server, and/or send it out via email.

  • Can I import an MP4 or FLV to Flash and make it an editable .fla file?

    Can I import an MP4 or FLV to Flash and make it an editable .fla file?

    Thanks for helping me.
    It's a vector animation that was made in flash and exported into a swf I believe and then posted on a website and on youtube. I have the mp4 ad the flv that I have converted from the online file using an online tool. I would like to use it as a base for my own video and just switch out some of the frames and characters/backgrounds - is that possible in Premier?

  • Can I take a song from my iTunes library and make it a ringtone on my iPhone 4? If so how. Thanks

    Can I take a song from my iTunes library and make it a ringtone for my iPhone 4  if so how  thanks

    http://osxdaily.com/2010/09/04/make-free-iphone-ringtones-in-itunes-10/

  • Flyweight Pattern use with multiple GUI components

    Hi,
    I am creating a simple application and I would like your advice on wether I should use the flyweight pattern or not.
    My application is essentially a GUI front to a repository of small images. The GUI (in its simplest form) is a single window that will display all the images with their names in a clickable thumbnail format. The user will be able to select an thumbnail icon, drag it and move it around pretty much like the icons on your computer desktop.
    The easiest way to do that is probably to load each image and its name into a JLabel, add it in a JFrame and write just few lines of code (say by extending the JLabel class) to handle mouse pressed/dragged events in order to move the label around. The rest will be taken care of by the swing functinality (e.g. painting etc).
    However, I am considering using the flyweight pattern for efficiency but I am not sure if it is appropriate. So far I have seen simplistic examples of its use (apart from JTree) where the pattern is used to paint dozens of lines on the screen or the borders of components. But what happens if instead of lines or borders the objects in question are interactive GUI components such as my thumbnails? how does the flyweight pattern work in this case?
    For example if I create just a single JLabel and use it to paint all my icons that's great! but what happens with mouse events? what happens when I want to drag a thumbnail over another one and how the partial repainting of the thumbnail below should be handled?
    Am I missing something here, or in order to implement the flyiweight pattern in this case I will have to write endless lines of code to replicate the functionality that swing arleady provides in each JComponent? (e.g. targetting of mouse events, repainting etc)
    Cheers,
    Kyri

    I don't think Flyweight applies, because you really don't want to share any UI component that generates events unless the response is the same for all of them.
    If you read Flyweight, I think it was intended for things like caching the first 128 Integers, etc. - think finite, countable, immutable things. I don't think UI elements apply.
    %

  • Can I record my scrolling thru a paused video and make it a video?

    Using ISight I record a clip. When I use the mouse and scroll thru the clip while it is paused I get some great effects. Can I record what I am doing and make it into video footage?
    Any help in this matter would be greatly appreciated.

    Dear Quick Time Kirk,
    I'm sorry that I am a newbee to the Mac software , but I am. I have an Imac that I purchased 2 weeks ago. I don't know if I have Imovie HD or Imovie HD 6. Where would I find this SnapZ Pro X? Probably on the more expensive Pro Mac???
    I appreciate your help in this matter.
    Rudd

  • Multi-Threaded gui components and accessor methods

    hello, I'm working on a small gui component which makes use of swingworker to deal with time consuming methods.
    My question is what is the best way to handle accessor methods for example to tackle the following code scenario:
    MyComponent myComponent = new MyComponent();
    myComponent.render(); // long task handed out to a thread
    myComponent.getVariable(); // will only return correct value if render() has completed
    Is the best option to use a Listener and fire a 'render completed' event?
    Thanks for any ideas,
    bm

    I think that's good approach to go with.
    Sai Pullabhotla.

  • Is there a way to select multiple audio tracks and make all of them stereo pair at the same time?

    I selected multiple tracks, pressed "option L" but was not able to make multiple clips stereo pair at the same time.

    If I remember correctly it is not possible modify a group of selected clips on the timeline with the Stereo Pair command - unless all the selected clips have exactly the same properties - such as being linked to  video clips, etc. So you have to manually go through and select the dual mono tracks you want to pair individually or in smaller groups to be able to apply the Stereo Pair command.
    If you select a bunch (a couple)  of clips, and go to the menu Modify, you will see if Stereo Pair is grayed out or not. If it is grayed out, then you can't apply it to those clips as a group, but you probably will be able to apply it if you make smaller selections of clips.
    MtD

  • GUI components always make me confuse!

    Hi all!
    Firstly, The problem I 've just encountered is that: I 'd like to add a JLabel with an icon onto the contentPane of the JFrame, But the Icon canot be drawn. Tell me why?
    This is the code:
    import javax.swing.*;
    import java.awt.*;
    class TestLabel extends JFrame {
         public TestLabel(String title) {
              super(title);
              ImageIcon icon = new ImageIcon(getToolkit().getImage("./images/chat.bmp"));
              JLabel lb = new JLabel( icon);
              this.getContentPane ().add(lb, BorderLayout.CENTER);
              this.setSize(300, 300);
              this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
              this.show();
         public static void main(String [] args) {
              new TestLabel("Test Label with Icon");
    Secondly: I would like to make an introduction for my application. So I creat an introduce canvas and then add some text and an Image on to it. But the Image can't not be displayed anyway. I'm going to be crazy with every thing!!!. Help me as soon as posible. This is the code of the Canvas ( JPanel). To test how things are, would you please creat a JFrame and add it on to the contentpane of the frame. Thanks!
    package caro;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.image.*;
    * <p>Title: Caro Game</p>
    * <p>Description: Two player caro game, playing through a Local Area Network</p>
    * <p>Copyright: Copyright (c) 2004 Group 8 - Tin 4 - K46</p>
    * <p>Company: FIT - HUT</p>
    * @author PhuongVM, AnhLT, KienNT, AnhNT
    * @version 1.0
    class IntroduceCanvas extends JPanel {
    private Color pink = new Color(255, 200, 200);
    private Color blue = new Color(150, 200, 255);
    private int w, h;
    private int edge = 16;
    private static final String title = "Caro Game";
    private static final String name = "Version 1.0-2004";
    private static final String foot = "Group 8 - Tin 4 - K46";
    private static final String subFoot = "FIT - HUT";
    private Font namefont, titlefont, footfont;
    Image hutImg;
    public IntroduceCanvas() {
    titlefont = new Font("SansSerif", Font.BOLD, 58);
    namefont = new Font("SansSerif", Font.BOLD, 18);
    footfont = new Font("SansSerif", Font.BOLD, 12);
    hutImg = getToolkit().getImage("./images/intro.jpg");
    // draw the specify String s with specify font, color and position
    private void d(Graphics g, String s, Color c, Font f, int y, int off) {
    g.setFont(f);
    FontMetrics fm = g.getFontMetrics();
    g.setColor(c);
    g.drawString(s, (w - fm.stringWidth(s)) / 2 + off, y + off);
    //Overide the paint method from the parent
    public void paintComponent(Graphics g) {
    //get the size of the window.
    Dimension d = getSize();
    w = d.width;
    h = d.height;
    //set the back ground color to CYAN
    g.setColor(Color.CYAN);
    g.fillRect(0, 0, w, h);
    // draw a blue 3D rectangle to put introduction
    g.setColor(blue);
    g.fill3DRect(edge, edge, w - 2 * edge, h - 2 * edge, true);
    //draw information and logo on to the rectangle
    g.clearRect(w/2 - 100/2, edge, 100, 140);
    g.drawImage(hutImg, w/2 - 100/2, edge, 100, 140, this);
    d(g, title, Color.black, titlefont, h / 2, 1);
    d(g, title, Color.white, titlefont, h / 2, -1);
    d(g, title, Color.pink, titlefont, h /2 , 0);
    d(g, name, Color.black, namefont, h * 3 / 4, 0);
    d(g, foot, Color.black, footfont, h * 9/11, 0);
    d(g, subFoot, Color.black, footfont, h * 7/8, 0);
    Thanks!!

    Hi all!
    Firstly, The problem I 've just encountered is that: I 'd like to add a JLabel with an icon onto the contentPane of the JFrame, But the Icon canot be drawn. Tell me why?
    This is the code:
    import javax.swing.*;
    import java.awt.*;
    class TestLabel extends JFrame {
    public TestLabel(String title) {
    super(title);
    ImageIcon icon = new ImageIcon(getToolkit().getImage("./images/chat.bmp"));
    JLabel lb = new JLabel( icon);
    this.getContentPane ().add(lb, BorderLayout.CENTER);
    this.setSize(300, 300);
    this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
    this.show();
    public static void main(String [] args) {
    new TestLabel("Test Label with Icon");
    Secondly: I would like to make an introduction for my application. So I creat an introduce canvas and then add some text and an Image on to it. But the Image can't not be displayed anyway. I'm going to be crazy with every thing!!!. Help me as soon as posible. This is the code of the Canvas ( JPanel). To test how things are, would you please creat a JFrame and add it on to the contentpane of the frame. Thanks!
    package caro;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.image.*;
    * <p>Title: Caro Game</p>
    * <p>Description: Two player caro game, playing through a Local Area Network</p>
    * <p>Copyright: Copyright (c) 2004 Group 8 - Tin 4 - K46</p>
    * <p>Company: FIT - HUT</p>
    * @author PhuongVM, AnhLT, KienNT, AnhNT
    * @version 1.0
    class IntroduceCanvas extends JPanel {
      private Color pink = new Color(255, 200, 200);
      private Color blue = new Color(150, 200, 255);
      private int w, h;
      private int edge = 16;
      private static final String title = "Caro Game";
      private static final String name = "Version 1.0-2004";
      private static final String foot = "Group 8 - Tin 4 - K46";
      private static final String subFoot = "FIT - HUT";
      private Font namefont, titlefont, footfont;
      Image hutImg;
      public IntroduceCanvas() {
        titlefont = new Font("SansSerif", Font.BOLD, 58);
        namefont = new Font("SansSerif", Font.BOLD, 18);
        footfont = new Font("SansSerif", Font.BOLD, 12);
        hutImg = getToolkit().getImage("./images/intro.jpg");
    // draw the specify String s with specify font, color and position
      private void d(Graphics g, String s, Color c, Font f, int y, int off) {
        g.setFont(f);
        FontMetrics fm = g.getFontMetrics();
        g.setColor(c);
        g.drawString(s, (w - fm.stringWidth(s)) / 2 + off, y + off);
    //Overide the paint method from the parent
      public void paintComponent(Graphics g) {
    //get the size of the window.
        Dimension d = getSize();
        w = d.width;
        h = d.height;
      //set the back ground color to CYAN
        g.setColor(Color.CYAN);
        g.fillRect(0, 0, w, h);
    // draw a blue 3D rectangle to put introduction
        g.setColor(blue);
        g.fill3DRect(edge, edge, w - 2 * edge, h - 2 * edge, true);
    //draw information and logo on to the rectangle
        g.clearRect(w/2 - 100/2, edge, 100, 140);
        g.drawImage(hutImg, w/2 - 100/2, edge, 100, 140, this);
        d(g, title, Color.black, titlefont, h / 2, 1);
        d(g, title, Color.white, titlefont, h / 2, -1);
        d(g, title, Color.pink, titlefont, h /2 , 0);
        d(g, name, Color.black, namefont, h * 3 / 4, 0);
        d(g, foot, Color.black, footfont, h * 9/11, 0);
        d(g, subFoot, Color.black, footfont, h * 7/8, 0);
    //??????????????????????????????????????????????????????????????????????????????Sorry! in the last post I don't know that our forum suport the  tag.
    Thanks for informing me!
    Thanks!

  • How can I apply a new style with a snippet and make DW remove artifacts of the old style?

    Hello,
    I am using Dreamweaver CS5 on Windows XP SP3. My problem seems simple but the resolution remains elusive.
    Let's say I am editing pasted-in text from MS Word that DW has auto-formatted. I highlight some text and use a snippet to enclose the text in h2.
    Instead of deleting the former style and replacing it with h2, DW applies the h2, but copies the old style, enclosing nothing, and bumps it to the next line. If the old style included a paragraph tag, that throws in extra white space. For nothing at all.
    Now, this seems like a minor thing, but it's not so minor when you are trying to quickly prepare a large document with various header styles. Having to make dozens of edits that I think should be completely unnecessary becomes a real burden.
    Is there a way to enclose a bit of text in a new style with a snippet without having the old style stick around?
    Thanks for any and all replies!
    Michael Salmons

    Maybe auto-format is not the correct terminology, but DW does interpret MS Word formatting in some way,and in a way I cannot control (well, I can to a limited degree). The term that popped into my head describing this process was automatic formatting.
    I don't really want to paste in as text, then I have to touch everything. I mean, I do frequently end up touching everything in a document anyway, but if any decisions can be "automated," I like to at least give it a try.
    DW makes mostly good guesses* about Word formatting (*or whatever mechanism translates word formatting to html in DW). Even if it is just a little wrong, it saves me a lot of time. <p><strong> can be converted to <h2> faster than text that only has a CRLF to distinguish it from surrounding text.
    I'm not mixing any styles. I control the style absolutely. I would just like to know how to use snippets in a way that truly replaces the Word-suggested tags rather than preserving them for no good reason. Perhaps there is no way to do that, or I so fundamentally misunderstand snippets I am fooling myself.

  • How can I put some text on a circular shape and make it visible in a Picture?

    I work with LabVIEW 5.1.1 (FDS), the Picture Control Toolkit and IMAQ 4.1.1.
    I'd like to make some text to flow on a circular shape of given radius just like I can do with the most common graphic programs like CorelDraw!
    How can I do?

    A new overlay VI was developed to address the need to add text to an image easily.
    IMAQ Overlay Text (Functions >> Vision Utilities >> Overlay).
    - It is available in IMAQ Vision 6.0 (which requires LabVIEW 5.1 or greater).
    It will allow you to rotate text, but it currently does not support circular shapes.

  • I can't make my logo into a vector image and make the background transparent

    I have a logo in psd that I bring into illustrator. I need to turn it into a vector image because it's going on a billboard. But when I do I can't get rid of the white background, make it transparent. Can anyone offer any solutions?

    Click on the properties icon in the top tool bar and choose ignore white, then the trace will trace everything except the white.

  • How can I set a website "blog" via Bussines Catalyst and make modules out of blog posts.

    Hi! I'm used to work with Muse but I want to start integrating Muse with Business Catalyst. I'm trying to make a "News Website" but I think it can me managed like a blog. I wanted to know if it can be done the way I designed it in Illustrator...So I would post blog entries from Business Catalyst and The Post Title and a little description would appear in these "modules" So I wanted to knwo how to set it up in Business Catalyst.
    As I said I'm really new to Business Catalyst, I've watched some tutorials but I really can't get the hang of it so If someone could help me and explain me step by step I would be inmmensely aprecciated!

    But so, If I'm getting the "look and feel" in muse I get the postlist blog module and insert it as an HTML element in Muse but in rectangle forms? and I set it in several rectangles or is there a way Business Catalyst Knows that when there's a new post order it and show it in rectangles of x and x px  separated by so much px and such, the styles I can handle, I got a friend who knows CSS3 but we don't get the modules and how do we connect BC znd Muse or as I said how to tell BC to roder and show new post like that...

  • Can I write a Java Program in Narrative view and make it work?

    Hi All,
    I got a requirement which demands me to write a java program in narrative view. As per my knowledge its not possible..........but do you guys have any work around or any other way to get that java program run when the report runs and the out must be seen on the dashboard???
    Thanks in advance,
    DK

    Joe thanks for the reply. I would like to communicate with a JavaScript API (MapQuest) by declaring a Proxy server and port number to communicate. Or I can directly use Java SDK to display maps.
    This is more a general question. If I can execute a java program then I will try doing many things.
    Thanks,
    DK

Maybe you are looking for

  • Lost iweb pages after format.

    I started my website when i had ilife 06. Now i had to reformat and have loas all mt saved iweb things.... How do i connect iweb upto my .mac site again? is there a way?

  • Clamshell mode macbook any dangers?

    hey, well i just got myself a nice 32" HD TV that i also want to use as the main display for my mac book core duo. just want to know if there are any issues with using the macbook mainly in clamshell mode. have heard reports that over heating is an i

  • Can I leverage Skype Lync O365 integration for full phone system?

    Have O365 enterprise and need new phone system for startup.  Can I leverage Skype for voice account and leverage Lync/ exchange features together? we are want no on premise environment. can I do this without Lync server?  if not,  does Lync server ex

  • Mapping for INBOUND sales data

    Hi All, I am working on SAP-POS integration for a retailer. My question is on mapping of inbound sales data with the Idoc - wpuums01. Partner profiles are of type - Customer -  and also there will be a seperate partner profile for each store. But, In

  • BAPI to validate data in customized fields of transaction MIGO

    Hi, I have a requirement where we need to add two custom fields to the header tab of MIGO screen. Please let me know if there is any BAPI existing to validate the data entered? If yes, how do we implement it? Thanks Shanthi