简体   繁体   中英

How to paint text directly onto a JFrame without using a Jpanel in Java?

I know you are able to modify paintcomponent in order to paint to a Jpanel, however I am trying to make a simple dialog box and do not desire for any of the minimize or maximize buttons to be on the frame (hence why it's undecorated), and do not want the buttons that come with using JPanel or JOptionPane to be on it either. If any of you know how to make an undecorate JPanel to add that would work as well, but if you know how to make drawString paint onto a JFrame that would be nice as well. Here is how far I have gotten so far, if any of you could explain why its not actually drawing the string to the JFrame that would be helpful. http://pastebin.com/vfSCnaF7

Why not just use a JLabel?

    JLabel l = new JLabel("Text");
    frame.add(l);

Or do you need the exact positioning you get with drawString()?

You should not override the paint() method.

You can add a JPanel and still have an undecorated window.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM