線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:903
推到 Plurk!
推到 Facebook!

JLabel 呈現的困擾

尚未結案
ParchiYoung
一般會員


發表:2
回覆:3
積分:1
註冊:2003-04-09

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-10-04 11:16:00 IP:211.22.xxx.xxx 未訂閱
此程式的用途是當按下上方的按鈕,在底下 JPanel 容器內增加一個 JLabel 元件。我測試過當按下按鈕時,JPanel 容器是會增加一個JLabel 元件,但要看到此 JLabel 元件須要改變視窗的大小。請各位大大幫忙一下…,如何按下按鈕時,立即能在下方JPanel 看到 JLabel 元件,謝謝。 import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ShowJLabel extends JFrame{ JButton button = new JButton("秀一下"); JPanel panel = new JPanel(); Container content; public ShowJLabel(){ super("Frame Title"); content = this.getContentPane(); content.setLayout(null); button.setBounds(10,10,100,30); button.addActionListener(new ShowJLabel_button_actionAdapter(this)); content.add(button); panel.setBounds(0,45,120,80); panel.setBorder(BorderFactory.createRaisedBevelBorder()); content.add(panel); this.setSize(new Dimension(130,170)); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); } public void button_actionPerformed(ActionEvent e){ panel.add(new Label("我秀我秀!!")); } public static void main(String args[]){ new ShowJLabel(); } } class ShowJLabel_button_actionAdapter implements java.awt.event.ActionListener{ ShowJLabel SJL; ShowJLabel_button_actionAdapter(ShowJLabel SJL){ this.SJL = SJL; } public void actionPerformed(ActionEvent e){ SJL.button_actionPerformed(e); } }
neoart
版主


發表:22
回覆:582
積分:425
註冊:2003-05-09

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-10-04 22:26:21 IP:61.56.xxx.xxx 未訂閱
public void button_actionPerformed(ActionEvent e){ panel.add(new Label("我秀我秀!!")); panel.repaint(); panle.validate(); }
系統時間:2024-05-20 9:19:47
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!