【JAVA語言程式設計基礎篇】--圖形化使用者介面基礎--Swing GUI組件的公用特性__JAVA

來源:互聯網
上載者:User

package chapter12;import java.awt.Color;import java.awt.FlowLayout;import java.awt.Font;import java.awt.GridLayout;import javax.swing.JPanel;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.border.LineBorder;//線框import javax.swing.border.TitledBorder;//標題框@SuppressWarnings("serial")public class TestSwingCommonFeatures extends JFrame{public TestSwingCommonFeatures(){JPanel p1 = new JPanel (new FlowLayout(FlowLayout.LEFT,2,2));JButton jbtleft = new JButton("left");JButton jbtcenter = new JButton("CENTER");JButton jbtright = new JButton("right");jbtleft.setBackground(Color.white);jbtcenter.setForeground(Color.green);jbtright.setToolTipText("this is the right button");p1.add(jbtleft);p1.add(jbtcenter);p1.add(jbtright);p1.setBorder(new TitledBorder("three buttons"));//-------------------------------------//Font largeFont =new Font ("TimesRoman",Font.BOLD,20);//字型JPanel p2 = new JPanel (new FlowLayout(FlowLayout.LEFT,5,5));JButton jbtred = new JButton ("red");JButton jbtorange = new JButton("orange");jbtred.setFont(largeFont);jbtred.setBackground(Color.red);jbtorange.setForeground(Color.orange);jbtorange.setToolTipText("this is a orange button");p2.add(jbtred);p2.add(jbtorange);p2.setBorder(new LineBorder(Color.green,4));//被下一行覆蓋p2.setBorder(new TitledBorder("a"));p2.setLayout(new GridLayout(1,2,1,10));setLayout(new FlowLayout(FlowLayout.LEFT,30,30));setLayout(new GridLayout(1,2,5,10));//下一行有一個新的setlayout 這一樣的setlayout被覆蓋,就不顯示了add(p1);add(p2);}public static void main(String[] args) {JFrame frame = new TestSwingCommonFeatures();frame.setTitle("test swing common features");frame.setSize(500, 150);frame.setLocationRelativeTo(null);//放中間frame.setVisible(true);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}}




展示

Font 字型

Color 顏色

Border 框




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.