简体   繁体   English

向 JFrame 窗口的边框添加标题

[英]Adding a title to the border of a JFrame Window

I'm trying to add a title to the border of a JFrame Window, can anyone tell me how can I do this?我正在尝试向 JFrame 窗口的边框添加标题,谁能告诉我我该怎么做? I am using NetBeans我正在使用 NetBeans

The title should be in this position:标题应该在这个位置: 在此处输入图片说明

This is what I tried so far:这是我到目前为止尝试过的:

package cinema.booking.system;

import javax.swing.JFrame;
import javax.swing.border.TitledBorder;
import javax.*;

/**
 * @author chriz
 */    
public class About extends javax.swing.JFrame {

    /**
     * Creates new form About
     */
    public About() {
        initComponents();
        JFrame frame = new JFrame("Welcome"):
        frame.setTitle("Welcome");
    }
}

There are two ways to set the JFrame title:有两种方法可以设置 JFrame 标题:

I) Set the JFrame title when you construct your JFrame: I)在构建 JFrame 时设置 JFrame 标题:

JFrame jframe = new JFrame("Title");

II) Once you have a valid JFrame object, you can call the setTitle method of the JFrame class: II)一旦有了有效的 JFrame 对象,就可以调用 JFrame 类的 setTitle 方法:

jframe.setTitle("Title");

This is very simple.这很简单。 You can do one of the following:您可以执行以下操作之一:

  1. Use Frame#setTitle(java.lang.String)使用Frame#setTitle(java.lang.String)
  2. Use JFrame#JFrame(java.lang.String)使用JFrame#JFrame(java.lang.String)

Since your class About extends JFrame , can just use the super keyword to solve all your life's problems.由于您的类About扩展了JFrame ,因此只需使用super关键字即可解决您生活中的所有问题。 You can either use the superclass constructor, or invoke the setTitle method:您可以使用超类构造函数,也可以调用setTitle方法:

public About() {
    super("Welcome");
    initComponents();
}

or或者

public About() {
    initComponents();
    super.setTitle("Welcome");
}

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

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