❶ 在java流布局中怎麼設置按鈕的位置
流布局中你只能安排按鈕是從中間或是兩邊的排法,想要自己設置組件位置的話可以使用絕對布局
❷ java swing怎麼控制按鈕的位置啊
你可以將容器的整體布局設置為FlowLayout,然後在FlowLayout中添加一個Box布局,Box再添加3個部分,分別是表格、標簽和按鈕,兩個按鈕可以在用一個再新建一個Box對象並添加進去,下面是代碼:
import javax.swing.*;
import java.awt.*;
public class test extends JFrame{
public test()
{
setSize(300,200);
setLocationRelativeTo(null); //使窗體居中顯示
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());
setTitle("用戶信息");
String str[] = {"屬性","信息"};
Object str2[][]={{"姓名",""},{"職工號",""},{"身份證號",""},{"性別",""},{"出生年月",""}};
JTable table = new JTable(str2,str);
JButton Button1 = new JButton("修改信息");
JButton Button2 = new JButton("修改密碼");
JLabel Label = new JLabel("用戶:",JLabel.CENTER);
JScrollPane scrollpane = new JScrollPane(table);
Box box = Box.createVerticalBox();
Box buttonBox = Box.createHorizontalBox();
buttonBox.add(Button1);
buttonBox.add(Button2);
box.add(table);
box.add(Label);
box.add(buttonBox);
add(box);
}
public static void main(String []args)
{
test Test = new test();
Test.setVisible(true);
}
}
❸ 在java中如何改變按鈕位置
線程自結束自外部調用結束線程
線程CWinThread繼承結束自用AfxEndThread外部調用用PostThreadMessage(m_nThreadid, WM_QUIT,0,0);給線程發送消息線程結束其m_nThreadid線程ID
❹ java程序中 設置button的位置
用setBounds。比如
你的this.setLayout(new BorderLayout());
this.add(p1,BorderLayout.SOUTH);
this.add(p2,BorderLayout.CENTER);
你可以改成:
this.add(p1);
this.add(p2);
p1.setBounds(50,50,100,100);
你就會看到p1在界面的變化了。。
然後自己琢磨setBounds的用法。。。
❺ JAVA中怎麼設置jButton上圖標的位置
設置文本位置,圖片自然就移動了
applicateBtn.setVerticalTextPosition(JButton.CENTER);
applicateBtn.setHorizontalTextPosition(JButton.CENTER);
❻ Java中如何給JButton/JLabel定位置【高分懸賞】
必須容器用 null 布局
然後控制項 setBounds
bounds 包含的參數是位置(x,y)和大小(w,h)
這個 bounds 本來是布局管理器去控制計算的
既然 null 布局,不用管理器
只有自己去設置
只 setLocation 的話,只有位置,沒有大小——大小默認為 (0,0),所以不行
❼ java里button位置
你要先把面板的布局先設置為null空的,因為它默認的布局是邊界布局吧好像,如果那樣只能看到一個組件了,你在試試下面的我也沒試過猜的。
import java.awt.Container;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class caculator {
public static void main (String args[])
{
JFrame f=new JFrame("Form1");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(500, 300);
f.setVisible(true);
Container con=f.getContentPane();
JPanel panel=new JPanel();
panel.setLayout(null);
JButton butt=new JButton("開始");
JLabel lab1=new JLabel("a=");
JLabel lab2=new JLabel("b=");
butt.setBounds(40, 60, 30, 50);
lab1.setBounds(60, 60, 60, 60);
panel.add(butt);
panel.add(lab1);
panel.add(lab2);
con.add(panel);
}
}
❽ 在java語言中如何設置按鈕的位置
按鈕是組建,組建都是放在容器里的,你要設置組建位置,先要對容器布局,然後根據布局把按鈕放到想要放的地方,
默認布局是
borderlayout
按東南西北中排布,向四周擴散
常見的布局方式還有
flowlayout布局:從左到右排列,排滿後轉到下一行繼續
還有gridlayout
按
n行m列的網格布局
但你若要絕對定位位置,可以用null布局
比如你有一個容器p
p.setlayout(null);
button
button=new
button();
button.setbounds(int
x,inty,width,height)
希望對你有幫助
❾ 如何在java中自由設置button的位置
import javax.swing.ImageIcom; ImageIcon icon = new ImageIcon("圖片路徑"); jbutton.setIcon(icon);
❿ 如何設置按鈕的位置 在java語言中
按鈕是組建,組建都是放在容器里的,你要設置組建位置,先要對容器布局,然後根據布局把按鈕放到想要放的地方,
默認布局是 BorderLayout 按東南西北中排布,向四周擴散
常見的布局方式還有 FlowLayout布局:從左到右排列,排滿後轉到下一行繼續
還有GridLayout 按 n行m列的網格布局
但你若要絕對定位位置,可以用null布局
比如你有一個容器p
p.setLayout(null);
Button button=new Button();
button.setBounds(int x,inty,width,height)
希望對你有幫助