2011-02-01 9 views
2

私はウィンドウを最大化しようとすると、別の最大化されたウィンドウが表示されている間に、ウィンドウのレンダリングが残ります。Java Swingアプリケーションが誤動作しているのはなぜですか?


import java.awt.BorderLayout; 
import java.awt.FlowLayout; 
import java.awt.GridBagConstraints; 
import java.awt.GridBagLayout; 
import java.awt.GridLayout; 
import java.awt.Insets; 
import java.awt.event.ActionEvent; 
import java.awt.event.ActionListener; 

import javax.swing.JFrame; 
import javax.swing.JPanel; 
import javax.swing.JScrollPane; 
import javax.swing.JTabbedPane; 
import javax.swing.JTable; 
import javax.swing.table.DefaultTableModel; 
import javax.swing.*; 
import javax.swing.table.TableColumnModel; 


/** 
* @author ad * 
*/ 
public class Blotter { 

    private JFrame topFrame; 
    private JPanel mainContentPanel; 

    private JList unsubscribedFields; 
    private JList subscribedFields; 
    private JButton butSubscribe; 
    private JButton butUnsubscribe; 
    private JButton butApply; 
    private JButton butOk; 
    private JButton butCancel; 
    private JPanel panConfirm; 
    private JPanel panToggle; 
    private JPanel panBottom; 


    private JPanel panLeftList; 
    private JPanel panRightList; 
    private JPanel panSubcribe; 
    private JPanel panUnsubscribe; 


    /** 
    * @param args 
    */ 
    public Blotter(){ 
     topFrame = new JFrame("Subscription Fields"); 
     mainContentPanel = new JPanel(new BorderLayout()); 
     /* 
     butSubscribe = new JButton("-->"); 
     butUnsubscribe= new JButton("<--"); 
     butApply = new JButton("Apply"); 
     butOk = new JButton("OK"); 
     butCancel = new JButton("Cancel");*/ 
     createAndBuildGui(); 
    } 

    public static void main(String[] args) { 
     // TODO Auto-generated method stub 
     Blotter b = new Blotter(); 
     try { 
      UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
     b.createAndBuildGui(); 
     b.fillGUI(); 
    } 


    private void fillGUI() { 
     String[] someRow = {"S110","200","100","42","32"}; 

    } 

    public void createAndBuildGui() 
    { 



     panConfirm = new JPanel(new GridLayout(1,3,5,5)); 
     panToggle = new JPanel(new GridBagLayout()); 
     panBottom = new JPanel(new FlowLayout()); 



     butApply = new JButton("Apply"); 
     butOk = new JButton("OK"); 
     butCancel = new JButton("Cancel"); 


     unsubscribedFields = new JList(); 
     subscribedFields = new JList(); 
     butSubscribe = new JButton(">>>"); 
     butUnsubscribe = new JButton("<<<"); 


     panSubcribe = new JPanel(new BorderLayout()); 
     panUnsubscribe = new JPanel(new BorderLayout()); 
     panLeftList = new JPanel(new BorderLayout()); 
     panRightList = new JPanel(new BorderLayout()); 


     // GridBagConstraints(int gridx, int gridy, int gridwidth, 
     // int gridheight, double weightx, double weighty, 
     // int anchor, int fill, Insets insets, int ipadx, int ipady) 


     panLeftList.add(unsubscribedFields, BorderLayout.CENTER); 
     panRightList.add(subscribedFields, BorderLayout.CENTER); 
     panSubcribe.add(butSubscribe, BorderLayout.SOUTH); 
     panUnsubscribe.add(butUnsubscribe, BorderLayout.NORTH); 
     panToggle.add(panLeftList, 
       new GridBagConstraints(0, 0, 1, 2, 0.5, 1, GridBagConstraints.CENTER, 
         GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); 

     panToggle.add(panRightList, 
       new GridBagConstraints(2, 0, 1, 2, 0.5, 1, GridBagConstraints.CENTER, 
         GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); 

     panToggle.add(panSubcribe, 
       new GridBagConstraints(1, 0, 1, 1, 0, 0.5, GridBagConstraints.SOUTH, 
         GridBagConstraints.NONE, new Insets(0, 2, 4, 4), 0, 0)); 
     panToggle.add(panUnsubscribe, 
       new GridBagConstraints(1, 1, 1, 1, 0, 0.5, GridBagConstraints.NORTH, 
         GridBagConstraints.NONE, new Insets(0, 2, 4, 4), 0, 0)); 



     // Building bottom OK Apply Cancel panel. 
     panConfirm.add(butApply, 0); 
     panConfirm.add(butOk, 1); 
     panConfirm.add(butCancel, 2); 

     panBottom = new JPanel(new FlowLayout(FlowLayout.RIGHT)); 
     panBottom.add(panConfirm, BorderLayout.EAST); 



     // building main content panel 
     mainContentPanel.add(panToggle,BorderLayout.CENTER); 
     mainContentPanel.add(panBottom, BorderLayout.SOUTH); 
     topFrame.add(mainContentPanel); 


     topFrame.pack(); 
     topFrame.setVisible(true); 

     topFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

    } 

    protected void createPriceTable() { 
     // More fields : "Quantity Done","Quantity Open","PInst","State","Cancel State","Executing System","WaveID","Source System","TraderID","Average Price","LastExecutionPrice","ClientOrderTag","OldQuantityDone" 
     String[] columnNames = {"OrderId","Account","Symbol","Side","Quantity",}; 
     Object[][] o = new Object[0][columnNames.length]; 

    } 





} 
+0

私はあなたのコードを実行しますが、それはあなたのための "面倒なこと"です。スイングはコードが言うことを行います。 – PeterMmm

+0

私はそれを最大化すると、ウィンドウの元の小さな画像が残っています。もう一つの最大化されたウィンドウが現れています。マウスでサイズを変更すると、サイズ変更された単一のウィンドウが必要です。 – ada

+0

@ PeterMmm、すべてのコンポーネントが作成され、2回追加されます。私の答えを見てください。 – aioobe

答えて

0

それはあなたが使用しているレイアウトマネージャに依存します。例えば、BorderLayoutは、フレームサイズが変更されたときに要素を再描画することを知っています。残念ながら、どのウィンドウがあなたのために働いているのかは分かりませんが、私はあなたのコードでGridBagLayoutを見ました。おそらく、このレイアウト(このレイアウトの使用法)は、同様の動作を妨げるでしょう。

+0

使用中の特定のレイアウトマネージャーとは関係ありません。私の答えを見てください。 – aioobe

5

あなたはcreateAndBuildGui()を2度:mainに1回、コンストラクタに1回呼び出します。

public Blotter(){ 
    topFrame = new JFrame("Subscription Fields"); 
    mainContentPanel = new JPanel(new BorderLayout()); 
    // ... 
    createAndBuildGui(); <-------- 
} 

 

public static void main(String[] args) { 
    Blotter b = new Blotter(); 
    // ... 
    b.createAndBuildGui(); <-------- 
    b.fillGUI(); 
} 

あなたがそれらのいずれかを削除すると、それだけで正常に動作します。

+0

ありがとうたくさんの男 – ada

+0

ようこそ。 – aioobe

関連する問題