How can get a Graphics to draw line on screen?

How can get a Graphics to draw line on screen?
Now, I can get a Graphics to draw line based on component. For example JPanel, but I want to get a Graphics to draw line on screen.

By drawing on the screen, I assume you mean drawing outside the bounds of a top-level window like
JFrame or JDialog. You can't do that. At least, without going native and even then that's a dodgey thing
for any platform to let you do. One thing you can do is simulate it with a robot's screen capture:
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;
public class X {
    public static void main(String[] args) throws Exception {
        Rectangle bounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
        BufferedImage image = new Robot().createScreenCapture(bounds);
        Graphics2D g2 = image.createGraphics();
        g2.setStroke(new BasicStroke(20));
        g2.setPaint(Color.RED);
        g2.drawLine(0, 0, bounds.width, bounds.height);
        g2.drawLine(bounds.width, 0, 0, bounds.height);
        g2.dispose();
        JLabel label = new JLabel(new ImageIcon(image));
        label.addMouseListener(new MouseAdapter(){
            public void mousePressed(MouseEvent evt) {
                System.exit(0);
        JFrame f = new JFrame();
        f.setUndecorated(true);
        f.getContentPane().add(label);
        f.setBounds(bounds);
        f.setVisible(true);
}

Similar Messages

  • How can get my ipad to turn on when screen is black?

    Screen is black on my ipad and it won't turn on.

    Try resetting your iPad. Hold down the sleep and home keys for about 20 seconds. See if you can force it to reboot. If it works. you'll see a silver apple. If so, let go and let it finish.

  • How can I allow the application to line through a field that has been locked after being digitally signed?  We have multiple sections on a form with some fields being proposed information and other in another section having the approved information. once

    How can I allow the application to line through a field that has been locked after being digitally signed?
    We have multiple sections on a form with some fields being proposed information and other in another section having the approved information. once the approved information is entered we line through the proposed field so the data entry clerk won't pick up the wrong information.  However we are receiving an error when attempting to enter data  in the field which we have this edit.  Error property: line through cannot be set because doing so would violate the document permission setting.  any idea how we can get around this issue?

    You can control which fields are locked down after signing by setting up a collection. Then those that are not locked can be changed after signing. If this is not possible, then the line outs must occur prior to signing.

  • How can i produce this type of line chart (yield curve) by using flex2 charting?

    help! I am a flex newcomer, how can i produce this type of
    line chart (yield curve) by using flex2 charting? Anybody can teach
    me how can i customize the width of each scales as below of line
    chart? anybody know this?
    Click
    Here To See

    I need to show the X and Y Co-ordinate in a message when I click on the graphic's point.
    thanks for the tips, I´ll try to understand the sample program.
    Noguti

  • How can get a database like ****.SQL file for test in sqlplus in oracle8i

    How can get a database like ****.SQL file for test in sqlplus in oracle8i,I am a beginner,thanks

    I'll give it a guess as to what it is you want but I'm afraid you'll have to give some more information to go on. I appreciate it's difficult for people who are beginners or who don't have English as their first language.
    Are you trying to run a SQL file? From SQL*plus you can do either of these:
    SQL> start my_file
    or
    SQL> @my_file
    N.B.: if th efile has a .sql extension you don't need to include it, but you do for any other file extension e.g.
    SQL> @myfile.run
    Here is the page Vijay referred to:
    Re: Physical storage Checks & adding disk on server. I hope you find it useful.
    You will more helpful links (including links to the Oracle on-line manuals at this page:
    Re: How to attach a java bean in forms6i
    good luck, APC

  • How can I fill structure from the line with contetnt of a XML file inside?

    How can I fill structure from the line with contetnt of a XML file inside?
    I have array of lines with XML documents inside. All XML's have the same structure.
    I need to fill array of structures (with the same structure like given XML's) from data of these XML's.
    How can I do this? I am trying Transformation with ora:parseEscapedXML, but receive error: "XPath expression failed to execute.
    Error while processing xpath expression, the expression is "ora:processXSLT("Transformation_1.xsl", bpws:getVariableData("ProcessedFiles"))", the reason is javax.xml.transform.TransformerException: javax.xml.transform.TransformerException: Could not find function: parseEscapedXML.
    Please verify the xpath query."

    Ive posted the new code but now I'm getting a FileAlreadyExistException error. How do I handle this exception error correctly in my code?
    import java.io.IOException;
    import java.nio.file.FileAlreadyExistsException;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.xml.sax.SAXException;
    public class MyDomParser {
      public static void main(String[] args) {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      try {
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document doc = builder.parse("ENtemplate.xml");
      doc.normalize();
      NodeList rootNodes = doc.getElementsByTagName("templates");
      Node rootNode = rootNodes.item(0);
      Element rootElement = (Element) rootNode;
      NodeList templateList = rootElement.getElementsByTagName("template");
      for(int i=0; i < templateList.getLength(); i++) {
      Node theTemplate = templateList.item(i);
      Element templateElement = (Element) theTemplate;
      System.out.println(templateElement.getAttribute("name")+ ".xml");
      for(int i=0; i < templateList.getLength(); i++) {
      Node theTemplate = templateList.item(i);
      Element templateElement = (Element) theTemplate;
      String fileName = templateElement.getAttribute("name") + ".xml";
      Files.createFile(Paths.get(fileName));
      System.out.println("File" + ":" + fileName + ".xml created");
      } catch (ParserConfigurationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (SAXException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();

  • How can get total weight in shipment

    Hi,
    I want, How can get the total weight quantity in shipment (VT03N)? That is sum of delivery quantity of all line item.
    All ready, I have checked to table VTTP there only showing delivery number in field name VBELN.
    Is it possible please tell me which table through I can get the total weight quantity.
    Regards,
    Devendra

    Hi Prashanth,
    Thanks for reply,
    As suggested you, same think I used the logic and solved the problem.
    VTTP-TKUNM (Shipment Number)
    VTTP-VBELN (Pickup all delivery number)
    LIPS-VBELN (Give all delivery Number)
    LIPS-NTGEW (net weight) or LIPS-BRGEW (gross weight) sum up of all the quantities for the field.
    Regards,
    Devendra

  • How can get IHyphenatedWord?

    Hi
    how can get IHyphenatedWord? Will it return all  hyphenated words of a document?

    I'm already delving way too deep into this, experienced SDK programmers may be laughing at me ...
    But, yeah, I'd guess using the IWaxLine interface would be the correct choice here. IWaxLine represents an actual line, as laid out by the paragraph composer at duty, and so can tell you if its final word is broken or not.
    Some random googling turned up this:
    * IWaxLine points to a number of IWaxRuns
    * IWaxRun contains a starting text index and "the number of chars represented by this wax" (from the SDK Help)
    So -- still guessing -- you should have a pointer to the actual text that has been composed. Then you probably should go over its lines and check if LineEndsWithHyphen is true. If so, go over the wax runs of this line and gather the actual characters (perhaps that's also possible directly from IWaxLine). If you have gathered all the character of that line, you can scan for 'words', and that's between 'quotes' because you have to determine yourself what a 'word' is in this context.

  • How can I make a gray box or gray screen in Pages over a few lines of text?

    How can I make a gray box or gray screen in Pages over a few lines of text?

    Thanks. Almost what I was looking for.
    While that makes for a gray over the lines, it still does not form a box.
    Any other suggestions to form a solid rectangular gray box?

  • My Apple TV was set up with a different Apple ID than I have for my ITunes Account.  In other words I have multiple Apple ID's.  How can get these accounts to sync up?

    My Apple TV was set up with a different Apple ID than I have for my ITunes Account.  In other words I have multiple Apple ID's.  How can get these accounts to sync up?

    If you wish to use home sharing then you need to setup the Apple TV under your ID.

  • I loos my APPLE ID, I have a new one, how can get access to data stored in the old one?

    I loos my APPLE ID, Now I have a new one, how can get access to data stored in the old one?

    Do you have the email & password of the old Apple ID?

  • Imported slide show into PE11 and some pics rotated unexpectedly, How can get back to horizontal?

    Imported slide show into PE11 and some pics rotated unexpectedly, How can get back to horizontal?

    winkhi
    Just what are the pixel dimensions of these photos that are automatically rotating on you in Premiere Elements 11 workspace after being transferred there from the Elements Organizer Slideshow Editor? Do I have that correct? If so, how are you making the transfer....Edit with Premiere Elements Editor, Burn to Disc, or other as Elements Organizer 11 Slideshow Editor output?
    What is the scenario...from the camera to the computer hard drive, landscape; from the computer hard drive to the Elements Organizer 11 Slideshow Editor, landscape; from the Elements Organizer 11 Slideshow Editor to Premiere Elements 11 Project Assets/Timeline, rotated to Portrait?
    Do you find that the frequency of the problem is related to pixel dimensions, number of photos used? What is the format of these photos, jpg or other?
    Are you using the Rotation option in the Applied Effects Tab/Applied Effects Palette/Motion Panel expanded to correct the photo rotation?
    Just some thoughts for now.
    ATR
    ATR

  • How can i know the number of lines in field-symbol internal table

    how can i know the number of lines in field-symbol internal table

    Hi,
    If your field symbol has been defined as an internal table :
    Use std describe as
    Data: l type i.
    describe <fs> lines l.
    'l' will contain the number of lines as needed.
    FYI
    The size of this storage area in a field symbols depends on the number of table lines which is not fixed, but determined dynamically at runtime.
    Regards,
    Amit

  • How can get the console window name of the current form?

    How can get the console window name of the current form?

    Try the various get methods of the viewObject such as getQuery:
    http://www.oracle.com/webapps/online-help/jdeveloper/10.1.2/state/content/navId.4/navSetId._/vtAnchor.getQuery%28%29/vtTopicFile.bc4jjavadoc%7Crt%7Coracle%7Cjbo%7CViewObject%7Ehtml/

  • How can get emails on all devices?

    How can get emails on all devices? When I read an email on my mac, my iphone doesn't download it. How can I change that setting?? I need to have all emails and all my devices!

    It sounds like your using a POP3 email account versus IMAP. With a POP3 account if you do not have the settings configured to leave email on the server the problem you describe will occur. With Outlook 2010 (on a PC for example) you can go into the account settings and configure to leave email on the server. That way both devices will see the email. Check help for your Mac email program for instructions...
    http://www.serverintellect.com/support/email/outlook-leave-on-server/
    A better solution is if your email provider uses IMAP. IMAP sync email folders between multiple devices. Meaning any device will receive the email, all sent email can be seen on the devices. If you delete email from one device the email is deleted from all the other devices. Check with your email provider to see if they offer IMAP services.
    If they do not your choices are to 1) configure email on the Mac as illustrated in the link above or 2) change email providers to something like Gmail or Outlook.com (as examples).
    Also see this for the iPad...
    Using a POP account with more than one device - Apple Support
    FWIW I use Cox IMAP email and fully sync email between a Win 8.1 Update 1 laptop, a Win 7 desktop, an iPad 4, an iPhone 4 and an iPhone 5S.

Maybe you are looking for

  • Problems downloading songs from Match to a 5th Generation iPod

    I have about 16,000 songs in my library in iTunes on a Windows 7 laptop, and have successfully turned on and synced with Match, with a paid subscription. Now I want to download songs from my library to a 5th Generation iPod. Whwn I connect the iPod t

  • Why are bookmarks generated intermittently when PDF created using EXCEL VBA?

    I have Windows 7 installed and Acrobat Pro 9 installed. There is an EXCEL application that creates PDFs successfully. Howver, bookmarks are generated sometimes and sometimes they are not generated. This happens without changing any code. I am at my w

  • Invalid License module error

    Hi, I have just updated my version of Crystal Reports XI to Crystal Reports XI Release 2 SP4 and have installed fix packs 4.2 to 4.5 in order to resolve some problems I've been getting with sub reports. I have changed my Visual Studio Installer packa

  • Cannot click on open on Mac Pro

    I wonder if anyone can assist as my Mac Pro Computer rebbots but cannot click on any icon even though mouse working. Many Thanks Minstrel 1 After 3rd Boot the problem self-resovled. Thank You

  • Newline problem in Textbox

    Hi, Sorry if my question sounds pretty noobish since I am new to JavaFX. I have a problem with inserting newline into JavaFX's textbox (with multi-lines allowed). I realize that JavaFX's textbox keeps replacing the newline character '\n' with a blank