Need help in simple code for LayeredPane

Hi,
here is my simple code for displaying layered pane,
why is it not working, when i comment label.setBounds();
also is there a way to have a transparent layer, like
what i want to do it
have ont JPanel with some painting on it
then i want to add one more JPanel over it which is transparent
Ashish
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
public class TestLayeredPaneFrame extends JFrame
     public TestLayeredPaneFrame()
          super("layered pane");
          this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
          JLayeredPane layeredPane =new JLayeredPane();
          layeredPane.setPreferredSize(new Dimension(400,600));
int x = 30;
int y = 30;
for (int i = 0; i < 3; i++) {
x +=30;
y +=30;
origin.x += offset;
origin.y += offset;
layeredPane.add(new myLabel(x ,y ), new Integer(i));
          Container contentPane = this.getContentPane();
          contentPane.add(layeredPane, BorderLayout.CENTER);
          JPanel panel = myGlassPane();
          this.setGlassPane(panel);
          setSize(new Dimension(800,600));
          this.setVisible(true);
     private JLabel myLabel(int x, int y)
     JLabel label = new JLabel("My Name");
label.setVerticalAlignment(JLabel.TOP);
label.setHorizontalAlignment(JLabel.CENTER);
label.setOpaque(true);
label.setBackground(Color.BLUE);
label.setForeground(Color.black);
label.setBorder(BorderFactory.createLineBorder(Color.black));
label.setBounds(x, y, 140, 140);     
return label;     
     public static void main(String args[])
TestLayeredPaneFrame tlp = new TestLayeredPaneFrame();
}     

Hi,
here is my simple code for displaying layered pane,
why is it not working, when i comment label.setBounds();
also is there a way to have a transparent layer, like
what i want to do it
have ont JPanel with some painting on it
then i want to add one more JPanel over it which is transparent
Ashish
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
public class TestLayeredPaneFrame extends JFrame
     public TestLayeredPaneFrame()
          super("layered pane");
          this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
          JLayeredPane layeredPane =new JLayeredPane();
          layeredPane.setPreferredSize(new Dimension(400,600));
int x = 30;
int y = 30;
for (int i = 0; i < 3; i++) {
x +=30;
y +=30;
origin.x += offset;
origin.y += offset;
layeredPane.add(new myLabel(x ,y ), new Integer(i));
          Container contentPane = this.getContentPane();
          contentPane.add(layeredPane, BorderLayout.CENTER);
          JPanel panel = myGlassPane();
          this.setGlassPane(panel);
          setSize(new Dimension(800,600));
          this.setVisible(true);
     private JLabel myLabel(int x, int y)
     JLabel label = new JLabel("My Name");
label.setVerticalAlignment(JLabel.TOP);
label.setHorizontalAlignment(JLabel.CENTER);
label.setOpaque(true);
label.setBackground(Color.BLUE);
label.setForeground(Color.black);
label.setBorder(BorderFactory.createLineBorder(Color.black));
label.setBounds(x, y, 140, 140);     
return label;     
     public static void main(String args[])
TestLayeredPaneFrame tlp = new TestLayeredPaneFrame();
}     

Similar Messages

  • Need help with LabVIEW code for motor control.

    Hi,
    My name is Sasi. I am a BME grad student working on my thesis topic of evaluating spine implants for low back pain. For this I am building a test machine that would apply pure moments to a spine specimen. I am using LabVIEW 8.5 to implement control of a brushless AC servo motor. My requirement is,
    Step 1: Initialize the motor.
    Step 2: Start moving it at a uniform RPM to the right (This RPM value too user can enter).
    Step
    3: While doin Step 2; simultaneously read torque cell data (Using DAQ
    asst.). DAQ o/p is from 0 V to 10 V; 0 V being -10 Nm n
                10 V being  +10 Nm
    Step 4: When Torque value reaches +10 Nm, i.e 10 V, the motor stops.
    Step
    5: From the position where motor stopped (i.e no need to reset to
    initial position) Start moving in the opposite direction at the same
                uniform RPM as in Step 2 while reading torque cell data.
    Step 6: Once again when torque reaches -10 Nm, i.e. 0 V, the motor should stop.
    Step 7: Repeat 'Step 2' to 'Step 6' 3 times.
    Step 8: Reset motor postion.
    Till now I have managed to get the motor to move forward n backward @ a desired vel, accl, n deceleration for 3 cycles. I am attaching my code. I am having problem inserting the code for reading DAQmx amidst all this. Can anyone help me out.
    Thnks,
    Sasi.
    Solved!
    Go to Solution.
    Attachments:
    Test_012609.vi ‏35 KB

    Hi Sasidhar,
    I took a look at your problem and I think I have a workable solution for you.  I definitely agree with Lynn's suggestion of using parallel loops.  This will allow the DAQmx portion to run uninhibited by the motion portion, and vice versa.  Plus, you only need to iterate the motion loop whenever the voltage level crosses a threshold.  So, by iterating on the motion code in the same loop that you are iterating on DAQmx code, you are essentially wasting processor.
    I created a VI that should do what you are wanting.  I tested it out myself and it works great.  You might have a tweak a few things to apply to your system (like motion board ID and DAQmx physical channel, etc.).  I used two parallel loops and event-based programming.  Basically the motion loop starts the motor spinning at the specified velocity.  Once the motor is spinning, it waits for the DAQmx loop to tell it that the voltage value has crossed the threshold.  When the voltage value exceeds the maximum threshold (which I set to a value slightly less than 10 to allow for jitter and saturation), the DAQmx loop signals the motion loop that it can finish its iteration.  The motion loop stops the motion, reverses the direction, and starts the motion again.  Once motion has started, it again waits for the DAQmx loop to tell it that a threshold has occurred, but this time, it is looking for a minimum threshold.  I used "Occurrences" to implement the event-based programming in LabVIEW.
    I have commented the code rather thouroughly, so hopefully the comments will answer any remaining questions.  The benefit of using event-based programming for this is that you save processor time, and your motion is more closely synchonized with the DAQmx.  Instead of iterating the motion loop as fast as you can, checking for updates each time, you just pause it, and wait for the other loop to tell you when to start up again.  In the mean time, the processor doesn't have to worry about iterating that loop over and over again.  Also, when the occurrence does occur, you catch it immediately, instead of having to wait until the next iteration.  Thus, you are more closely synchronized with the DAQmx portion of the code.
    I hope this will help you.  Please post back if you have any questions about the code or its implementation.  Good Luck!
    Message Edited by Wes P on 02-03-2009 05:18 PM
    Wes P
    Certified LabVIEW Developer
    Attachments:
    Motion and DAQ.vi ‏59 KB
    DAQmx Loop.png ‏24 KB
    Motion Loop.png ‏17 KB

  • Need help with Labview code for DAQmx

    I'm currently trying to write Labview code for some thesis research and am having problems.  I'm using the cDAQ 9172 with strain gage modules and two voltage input modules.  I'll be reading/recording a voltage from an external source on one channel, while recording strains and accelerations with the other channels.  I need to do all this simultaneously.
    Everything I've done to this point has been in SignalExpress so I'm not sure how to program any of this.  I also need to be able to calibrate the strain gages prior to each set of recordings.  Any help you guys could offer would be greatly appreciated.  Thanks.

    Hi,
    I'm not sure how much this will help you, but I've attached a screen dump of code from a project I did that sounds pretty similar to what you're working on. The code is from a subVI that I used to create the daqMX measurement task for my data acquisition. I was also using a 9172. This was written in 8.5, but the only thing that you may not have access to is the functions for null offset and shunt cal of the strain gage channels. Hopefully this will at least get you started on your way to setting this up.
    Andrew Carollo
    Attachments:
    create task.jpg ‏208 KB

  • Need help to write code for 'Print" button......!

    Hi all,
    I am working in oracle forms 6i.I am creating forms for ordering product/quantity(Entering quantity/product details). In my form i have "Print button" to print the quantity details which is in multi-record block(database item).Please help me of how to write code for print button. If u had any source code please post it.
    Please help asap......!
    Thanks
    regards,
    jame

    You haven't got an answer or a reply because this question is asked so many times.
    Why don't you search the forum to find them?

  • Beginner needs help with simple code.

    I just statrted learnind java, and I need some help with this simple program. For some reason everytime I enter my Farenheit value, the Celsius conversion returns as 0.0. Would really appreciate the help. Thanks.
    Here's the code:
    public class TempConverter
    public static void main(String[] args)
    double F = Double.parseDouble(args[0]);
    System.out.println("Temperature in Farenheit is: " + F);
    double C = 5 / 9;
    C *= (F - 32);
    System.out.println("Temperature in Celsius is: " + C);
    }

    double C = 5 / 9This considers "5" and "9" to be integers and does an integer division, discarding the remainder. The result of that division is 0. Trydouble C = 5.0/9.0;

  • Need help in the code for updating a record ( conditional update)

    all set
    Edited by: 871431 on Jul 9, 2011 6:30 PM

    871431 wrote:
    Hi
    I am looking to update a table which contains approved & unapproved records, for that date & fund combination it should allow only one unapproved record.
    what I did is check if the record is U if the incoming value is Unapproved for that fund & date combination raise error, but if I need to update that Unapproved record it raises error....so I need to update that record, and raise error if trying to insert another unapproved record.
    Hope I am clear....Not clear for me
    Help needed plsPlease realize & understand that everyone here speaks SQL
    please post DDL for table
    please provide sample/test data & then explain using actual test data what the results should be & why

  • Need help getting a code for photoshop

    I have had Adobe Photo Album Starter Edition 3.2 on my computer sinse 2007. and it has been registered . but every once in awhile it would say it is not registered but it still let me look at my pictures so i didnt worry about it. now it is doing it and i reregistered it again but this time it wont let me look at my pictures untill i enter a code that was spose to be emailed to me. it has been days now of me trying and i still am not getting no emails with a code, and i cant look at my pictures, and i had adobe erase my chip after it was done downloading. So those are the only copy i have of those pictures. Can you help me ? send me a doe to unlock it or something, please .....

    PS Starter is long a dead product. Whatever automatisms were in place to provide activation codes ondoubtedly no longer exist. As Wade said, contact support directly. Though I'm pretty certain they can't help you, either. Simply use anotehr image viewer/ editing program like PSE.
    Mylenium

  • Need help with html code for password logins

    I'm building a site and need to have a login page where multiple users can have unique usernames and passwords and then all be redirected to the same page within the same website.  Does anyone have any code advice or tips on how this can be done in iweb.  I getting stuck at the point in the code where I have to enter the site to be redirected to upon entering the correct username and password.  I would greatly appreciate any advice or tips.  Thanks

    Its done on the server rather than in iWeb....
    http://www.iwebformusicians.com/iWeb/Comments-Password-Protect.html

  • NEED HELP WITH REDEEMING CODE FOR OS LION!

    im running 10.6.8 and im trying to update to Lion , im qualifyed to update free apple has sent me a code to redeem on the mac app store but i says " the code you have entered is not recognised as a valid code."
    PLEASE HELP!

    IVE DONE IT, IF YOUR USING HOTMAIL EMAIL - CLICK DOWNLOAD ON THE ABOVE YOU MESSAGE AND A LINK SHOULD APPEAR, YOU SHOULD HAVE GOT ANOTHER EMAIL SAYING YOUR CODE - COPY AND PASTE THE CODE YOU GOT INTO THE LINK AND CLICK NEXT OR SOMETHING, THEN YOU SHOULD GET ANOTHER CODE AND GO TO MAC APP STORE ON YOUR LEFT YOU SHOULD HAVE "QUICK LINKS" AND UNDER THAT YOU SHOULD HAVE REDEEM CLICK THAT AND TYPE IN THE CODE YOU GOT FROM THE LINK THEN YOUR DONE!
    Ps. if you did not get the email check your junk/spam folders.

  • Need help writing a code for this program

    Design a code that reads a sentence and prints each individual word on a different line

    tsith's suggestion is excellent. Run it and see what happens. I just did that myself and doing so I learned something new about the Scanner class.
    Before you run it, add a couple of extra System.out.println for (hopefully) illustrating debugging purposes:
    import java.lang.String;
    import java.util.Scanner;
    public class Sentence {
        // main line of program
        public static void main(String[] args) {
            boolean z;
            String a;
            Scanner keyboard = new Scanner(System.in);
            System.out.print("Enter sentence: ");
            z = keyboard.hasNext();
            while (z) {
                System.out.println("z = " + z + ". Fetching the next word...");
                a = keyboard.next();
                System.out.println(a);
            System.out.println("Done!");
    }Let us know if the program ever prints "Done!" to the console. While you are waiting, read what the javadocs has to say about the Scanner class, and pay extra attention to what it says about the hasNext() and next() methods:
    http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scanner.html

  • Need help writing correct code for nested button

    This is the code on the main timeline.
    stop();
    garage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
    function mouseDownHandler(event:MouseEvent):void {
        gotoAndPlay("open");
    The movieClip gDoor is nested inside of garage and "open" is a label on that timeline.  I know the gotoAndPlay("open"); isn't correct.  How would i target the label on the nested timeline.
    the link below is to dowload the fla
    clienttestsite.x10.mx/beta/garage.fla

    The problem is that you have an event listener assigned to the garage, which is blocking/overriding interaction with anything inside of it.  When you click on the chest's button, you are still clicking on the garage, which does the gotoAndPlay("open")... where it stops at the stop();
    One way to get around this is to assign an instance name to the door and assign the opening code to that....
    stop();
    garage.door.addEventListener(MouseEvent.CLICK, openHandler);
    function openHandler(event:MouseEvent):void{
       garage.play();
    garage.chest.closeBtn.addEventListener(MouseEvent.CLICK, closeHandler);
    function closeHandler(event:MouseEvent):void{
       garage.gotoAndPlay("close");
    Notes: as shown in the code above...
    - use CLICK instead of MOUSE_DOWN.
    - in the openHandler use play() instead of gotoAndPlay("open"). You are already in the "open" frame, and it is only because the stop() is used up that it actuallys works.
    Doing what I explain above also makes it so that you can click the door to close things as well.

  • Need Help With Simple ABAP Code

    Hello,
    I'm loading data from a DSO (ZDTBMAJ) to an Infocube (ZCBRAD06). I need help with ABAP code to some of the logic in Start Routine. DSO has 2 fields: ZOCTDLINX & ZOCBRDMAJ.
    1. Need to populate ZOCPRODCD & ZOCREFNUM fields in Infocube:
        Logic:-
        Lookup /BI0/PMATERIAL, if /BIC/ZOCBRDMAJ = /BIC/OIZOCBRDMAJ
        then /BIC/ZOCPRODCD = ZOCPRODCD in Infocube
               /BIC/ZOCREFNUM = ZOCREFNUM in Infocube         
    2. Need to populate 0G_CWWTER field in Infocube:
        Logic:
        Lookup /BIC/PZOCTDLINX, if /BIC/ZOCTDLINX = BIC/OIZOCTDLINX
        then G_CWWTER = 0G_CWWTER in Infocube.
    I would need to read single row at a time.
    Thanks!

    I resolved it.

  • Need help in transcation code ime0

    I need help in transaction code ime0. I mean to say what is this TCode doing? What different Drill-down program means? Where I can use this report?
    Regards,
    Subhasish

    Hi
    Please check the link for help
    <a href="http://help.sap.com/saphelp_47x200/helpdata/EN/5c/8db33f555411d189660000e829fbbd/frameset.htm">CA - Drilldown Reporting</a>
    Hope it helps
    Anirban

  • Need help in developing BADI for IT0001

    Hi All,
    I need help in developing BADI for IT0001.
    On IT0001 create or change, there is need to update IT0017 with following data from IT0001
    -Company Code
    -Cost center
    -Business Area
    -Begin and End Date.
    Other fields from IT0017 need to be derived from Position and update in IT0017.
    Please guide me how I can address this. I do not want to go for dynamic action, as it is not getting evoked during background jobs.
    I am new to BADI development and will appreciate step by step instructions.
    Thanks

    Hi,
         follow the below steps to achive
    Steps:
    1.     Execute Business Add-In(BADI) transaction SE18
    2.     Enter BADI name i.e. HRPAD00INFTY and press the display
            button
    3.     Select menu option Implementation->Create
    4.     Give implementation a name such as Z_HRPAD00INFTY
    5.      You can now make any changes you require to the BADI within this
            implementation, for example choose the Interface tab there are 3 methods avialble
    6.     Double click on the method you want to change, you can now enter
            any code you require.
    7.      Please note to find out what import and export parameters a
            method has got return the original BADI definition
            (i.e. HRPAD00INFTY) and double click on the method name
            for example within HRPAD00INFTY contract is a method
    8.      When changes have been made activate the implementation
    <b>Reward points</b>
    Regards

  • I need help with this code error "unreachable statement"

    the error_
    F:\Java\Projects\Tools.java:51: unreachable statement <-----------------------------------------------------------------------------------------------------------------THIS
    int index;
    ^
    F:\Java\Projects\Tools.java:71: missing return statement
    }//end delete method
    ^
    F:\Java\Projects\Tools.java:86: missing return statement
    }//end getrecod
    ^
    3 errors
    import java.util.*;
    import javax.swing.*;
    import java.awt.*;
    public class Tools//tool class
    private int numberOfToolItems;
    private ToolItems[] toolArray = new ToolItems[10];
    public Tools()//array of tool
    numberOfToolItems = 0;
    for(int i = 0; i < toolArray.length; i++)//for loop to create the array tools
    toolArray[i] = new ToolItems();
    }//end for loop
    }//end of array of tools
    public int search(int id)//search mehtod
    int index = 0;
    while (index < numberOfToolItems)//while and if loop search
    if(toolArray[index].getID() == id)
    return index;
    else
    index ++;
    }//en while and if loop
    return -1;
    }//end search method
    public int insert(int id, int numberInStock, int quality, double basePrice, String nm)//insert method
    if(numberOfToolItems >= toolArray.length)
    return 0;
    int index;
    index = search(id); <-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------HERE
    if (index == -1)
    toolArray[index].assign(id,numberInStock, quality, basePrice,nm);
    numberInStock ++;
    return 1;
    }//end if index
    }//end if toolitem array
    return -1;
    }//end insert method
    public int delete(/*int id*/)//delete method
    }//end delete method
    public void display()//display method
    for(int i = 0; i < numberOfToolItems; i++)
    //toolArray.display(g,y,x);
    }//end display method
    public String getRecord(int i)//get record method
    // return toolArray[i].getName()+ "ID: "+toolArray[i].getID()
    }//end getrecod
    }//end class
    Edited by: ladsoftware on Oct 9, 2009 6:08 AM
    Edited by: ladsoftware on Oct 9, 2009 6:09 AM
    Edited by: ladsoftware on Oct 9, 2009 6:10 AM
    Edited by: ladsoftware on Oct 9, 2009 6:11 AM

    ladsoftware wrote:
    Subject: Re: I need help with this code error "unreachable statement"
    F:\Java\Projects\Tools.java:51: unreachable statement <-----------------------------------------------------------------------------------------------------------------THIS
    int index;
    ^
    F:\Java\Projects\Tools.java:71: missing return statement
    }//end delete method
    ^
    F:\Java\Projects\Tools.java:86: missing return statement
    }//end getrecod
    ^
    3 errorsThe compiler is telling you exactly what the problems are:
    public int insert(int id, int numberInStock, int quality, double basePrice, String nm)//insert method
    if(numberOfToolItems >= toolArray.length)
    return 0; // <<== HERE you return, so everyting in the if block after this is unreachable
    int index;
    index = search(id);  //< -----------------------------------------------------------------------------------------------------------------HERE
    if (index == -1)
    toolArray[index].assign(id,numberInStock, quality, basePrice,nm);
    numberInStock ++;
    return 1;
    }//end if index
    }//end if toolitem array
    return -1;
    }//end insert method
    public int delete(/*int id*/)//delete method
    // <<== HERE where is the return statement?
    }//end delete method
    public String getRecord(int i)//get record method
    // return toolArray.getName()+ "ID: "+toolArray[i].getID() <<== HERE you commented out the return statement
    }//end getrecod
    }//end class

Maybe you are looking for

  • I am having issues placing digital pictures in master templates in FCP 6

    Hello everyone, this is my first post but I have been using Mac's for some time now with basically no issues. I have two major issues: First off, I am trying to place digital pictures which are enormous in the master template drop boxes, when I do th

  • Conditional cross-references in InDesign?

    Hi folks, (We asked this question once before on the FrameMaker forums, and I'll try again here since we're now moving towards InDesign:) What we need is two types of crossreference formats - one for print, one for PDF/the web/any other hyperlinkable

  • Parallel Data Extraction from R3 to BI

    Dear Experts,    I am trying to execute Parallel data extraction from R3 Development to BI development.It was previously done smoothly .Without any changes its stop in parallel .Your suggestions are welcome. Regards SurendraJain

  • Codec for HD Quicktime?...

    I have a couple HD Clips that a friend gave me which are in Quicktime format and I want to include them in my Premiere CS4 Project. I try to bring them in and I get an error saying "Codec missing or unavailable" I tried then just opening the Quicktim

  • Variant Date

    Hi, There is an ABAP program step in a job. The program uses a variant which is having date. The attribute for the date field is RS_VARI_V_TODAY which would give currrent date. But the thing is when the job is manually run, the date is not provided a