简体   繁体   English

如何在Java中不使用Jpanel的情况下直接将文本绘制到JFrame上?

[英]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. 我知道您可以修改paintcomponent以便将其绘制为Jpanel,但是我试图制作一个简单的对话框,并且不希望任何最小化或最大化按钮出现在框架上(因此为何未修饰),也不希望使用JPanel或JOptionPane随附的按钮。 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. 如果你们中的任何一个知道如何制作一个未经修饰的JPanel都可以正常工作,但是如果您知道如何将drawString绘制到一个JFrame上也可以。 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. 如果你们中的任何一个可以解释为什么它实际上没有将字符串绘制到JFrame会有所帮助,这就是我到目前为止所取得的成就。 http://pastebin.com/vfSCnaF7 http://pastebin.com/vfSCnaF7

Why not just use a JLabel? 为什么不只使用JLabel?

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

Or do you need the exact positioning you get with drawString()? 还是您需要使用drawString()获得确切的位置?

You should not override the paint() method. 您不应覆盖paint()方法。

You can add a JPanel and still have an undecorated window. 您可以添加一个JPanel并仍然具有未修饰的窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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