日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

java.swing调难度_Java Swing BorderLayout调整了难度

發布時間:2025/3/15 java 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java.swing调难度_Java Swing BorderLayout调整了难度 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

你可以在你的情況下使用的是

GridLayout,這里有兩個JButtons會在JFrame調整大小時自行調整大小.

import java.awt.GridLayout;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.SwingUtilities;

public class Main extends JFrame {

public static void main(String[] args) {

SwingUtilities.invokeLater(new Runnable()

{

@Override

public void run()

{

JFrame window = new Main();

window.setVisible(true);

}

});

}

public Main() {

JButton east = new JButton("East");

JButton west = new JButton("West");

JPanel content = new JPanel();

content.setLayout(new GridLayout(1, 2));

content.add(east);

content.add(west);

setContentPane(content);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

pack();

}

}

此外,最好從EDT – Event Dispatch Thread運行與GUI相關的代碼,而不是從主線程運行.有關該主題的更多信息,請閱讀Concurrency in Swing.

最新編輯:根據要求的評論

使用GridBagLayout指定要提供的大小

import java.awt.Color;

import java.awt.GridBagConstraints;

import java.awt.GridBagLayout;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.SwingUtilities;

public class Main extends JFrame {

public static void main(String[] args) {

SwingUtilities.invokeLater(new Runnable()

{

@Override

public void run()

{

JFrame window = new Main();

window.setVisible(true);

}

});

}

public Main() {

JPanel east = new JPanel();

east.setOpaque(true);

east.setBackground(Color.WHITE);

JPanel west = new JPanel();

west.setOpaque(true);

west.setBackground(Color.BLUE);

JPanel content = new JPanel();

content.setLayout(new GridBagLayout());

GridBagConstraints gbc = new GridBagConstraints();

gbc.anchor = GridBagConstraints.FIRST_LINE_START;

gbc.fill = GridBagConstraints.BOTH;

gbc.weightx = 0.3;

gbc.weighty = 1.0;

gbc.gridx = 0;

gbc.gridy = 0;

content.add(east, gbc);

gbc.weightx = 0.7;

gbc.gridx = 1;

content.add(west, gbc);

setContentPane(content);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

pack();

}

}

總結

以上是生活随笔為你收集整理的java.swing调难度_Java Swing BorderLayout调整了难度的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。