簡體   English   中英

我如何制作這個圖形用戶界面?

[英]How do I make this GUI?

我的任務是使用“swing”在 Java 中制作 GUI,它是下圖的精確復制品。 它不必具有任何功能,它只是為了外觀。 但是,我無法找到或制作此圖像的這一部分,即右上角的“性別”框。 如何制作具有輪廓的透明框? 請幫幫我,謝謝!

我只想知道如何制作帶有“性別”標題的透明框。

這稱為TitledBorder

例子:

public class SwingTester {

   public static void main(String[] args) {
      createWindow();
   }

   private static void createWindow() {    
      JFrame frame = new JFrame("Swing Tester");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      createUI(frame);
      frame.setSize(560, 200);      
      frame.setLocationRelativeTo(null);  
      frame.setVisible(true);
   }

   private static void createUI(JFrame frame){
      //Create a border
      Border blackline = BorderFactory.createTitledBorder("Title");
      JPanel panel = new JPanel();
      LayoutManager layout = new FlowLayout();  
      panel.setLayout(layout);       

      JPanel panel1 = new JPanel();
      String spaces = "                   ";

      panel1.add(new JLabel(spaces + "Title border to JPanel" + spaces));  
      panel1.setBorder(blackline);

      panel.add(panel1);
      frame.getContentPane().add(panel, BorderLayout.CENTER);    
   }
}

在此處輸入圖片說明

對於您的情況,請使用您自己的標題更新此行:

Border blackline = BorderFactory.createTitledBorder("Title");  //change to gender

來源: https : //www.tutorialspoint.com/swingexamples/add_title_to_border_panel.htm

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM