導航:首頁 > 編程語言 > javaswing部署

javaswing部署

發布時間:2025-04-04 21:39:08

java Swing JPanel 怎麼修改默認布局

1.布局首先要理清思路,那一個組件放在哪個組件裡面,就如你的代碼他們分別是 JFrame f中放置了JPanel center,而JPanel center中又放置了5個testPanel[] t = new testPanel[5];
也就是說,你的5個test_shu對象的位置由center容器的布局方式決定即你的代碼22行處 private JPanel center = new JPanel(new FlowLayout());
這個布局方式決定,所以,而FlowLayout的布局方式的默認值是:

流式布局管理器把容器看成一個行集,好象平時在一張紙上寫字一樣,一行寫滿就換下一行。行高是用一行中的控制項高度決定的。FlowLayout是所有 JApplet/JApplet的默認布局。在生成流式布局時能夠指定顯示的對齊方式,默認情況下是居中(FlowLayout.CENTER)

FlowLayout() //生成一個默認的流式布局,組件在容器里居中,每個組件之間留下5個像素的距離.
FlowLayout(int alinment) //可以設定每行組件的對齊方式.
FlowLayout(int alignment,int horz,int vert) //設定對齊方式並設定組件水平和垂直的距離.
當容器的大小發生變化時,用FlowLayout管理的組件會發生變化,其變化規律是:組件的大小不變,但是相對位置會發生變化.

所以要達到你的效果,只需要將
22行處的代碼改成如下設置就可以了:

private JPanel center = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));

❷ java:求一個用swing來做小程序,我是用來修改配置文件用的,求代碼謝謝

XML文件(e:\data\dbconfigure.xml):
<?xml version="1.0" encoding="UTF-8"?>
<CONFIGUREDATA>
<CONFIGURE TYPE="SQL Server 2005">
<DRIVER>com.microsoft.sqlserver.jdbc.SQLServerDriver</DRIVER>
<URL>jdbc:sqlserver://localhost:1433;DatabaseName=DBName</URL>
<USERID>sa</USERID>
<PASSWORD>123</PASSWORD>
</CONFIGURE>
</CONFIGUREDATA>

Java程序(Test.java):

import java.io.File;
import java.io.FileOutputStream;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;

public class Test{
public static void main(String[] args){
try{
String filepath = "E:\\data\\dbconfigure.xml";

File file = new File(filepath);
SAXBuilder builder = new SAXBuilder();
Document document = (Document) builder.build(file);
Element root = document.getRootElement();
Element elem1 = root.getChild("CONFIGURE");

//修改密碼
elem1.getChild("PASSWORD").setText("123456");

//寫回XML文件
Format format=Format.getRawFormat();
format.setEncoding("UTF-8");
XMLOutputter output=new XMLOutputter(format);
output.output(document, new FileOutputStream(filepath));
}
catch(Exception e){
e.printStackTrace();
}
}
}

Swing省略。

閱讀全文

與javaswing部署相關的資料

熱點內容
2017互聯網java面試題 瀏覽:907
供求網站源碼 瀏覽:195
童程童美編程加盟怎麼樣 瀏覽:895
app美團如何下載 瀏覽:197
弄畫框用什麼app 瀏覽:814
java獲取網頁圖片 瀏覽:193
jsp集合對象轉json 瀏覽:231
文件櫃在cad裡面長啥樣 瀏覽:554
iphone手機文件保存在哪裡 瀏覽:817
解壓文件後要刷新 瀏覽:786
cc資料庫怎麼獲得時間 瀏覽:226
ug3d硬料開出怎麼編程 瀏覽:151
如何獲取文件Linux命令 瀏覽:981
大智慧軟體哪個版本最好 瀏覽:698
狼人殺自動主持app叫什麼 瀏覽:949
checkbox怎麼綁定資料庫 瀏覽:945
編程怎麼設置一分鍾開燈 瀏覽:754
如何把桌面文件發送到自己郵箱 瀏覽:498
校園網站怎麼看選修的課 瀏覽:59
大數據專業哪個最好 瀏覽:467

友情鏈接