導航:首頁 > 編程語言 > 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部署相關的資料

熱點內容
網路中常用的傳輸介質 瀏覽:518
文件如何使用 瀏覽:322
同步推密碼找回 瀏覽:865
樂高怎麼才能用電腦編程序 瀏覽:65
本機qq文件為什麼找不到 瀏覽:264
安卓qq空間免升級 瀏覽:490
linux如何刪除模塊驅動程序 瀏覽:193
at89c51c程序 瀏覽:329
怎麼創建word大綱文件 瀏覽:622
裊裊朗誦文件生成器 瀏覽:626
1054件文件是多少gb 瀏覽:371
高州禁養區內能養豬多少頭的文件 瀏覽:927
win8ico文件 瀏覽:949
仁和數控怎麼編程 瀏覽:381
項目文件夾圖片 瀏覽:87
怎麼在東芝電視安裝app 瀏覽:954
plc顯示數字怎麼編程 瀏覽:439
如何辨別假網站 瀏覽:711
寬頻用別人的賬號密碼 瀏覽:556
新app如何佔有市場 瀏覽:42

友情鏈接