JSplitPane仅在创建时Jframe内部的JTabbedPane内的当前选项卡中显示实际权重

时间:2016-11-28 13:07:57

标签: java swing jtabbedpane jsplitpane

这是我的主要课程

Class MainGuiFrame:

public class MainGuiFrame extends JFrame {
public static void main(String args[]) throws Exception {


    EventQueue.invokeLater(new Runnable() {
        public void run() {
            MainGuiFrame jf;
            try {
                jf = new MainGuiFrame();
                setLookAndFeel();
                jf.setVisible(true);
                jf.setExtendedState(JFrame.MAXIMIZED_BOTH);

            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    });
}







private JSplitPane jSplitPaneMapPlusFunctions;
private FileReadAndRunJpnl jpnlInputFile;
private JTabbedPane tabbedPane;

private final int widthCarMapAndButtons=650, heightCarMapAndButtons = 620;
private final int widthJpnlFunctions=650, heightJpnlFunctions=60;//+heightJpnlMapButtons;
private CarsDrawingJpnl jpnlCarDeckDrawing;
private CarsDrawingJpnl jpnlPlatformDeckDrawing;
private CarsDrawingJpnl jpnlTrailerDeckDrawing;


public MainGuiFrame() throws IOException {

    super( "Ferry Visualization");                      // invoke the JFrame constructor
    setSize(new Dimension(650,700));
    setMinimumSize(new Dimension(650,700));
    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

    setLayout(new BorderLayout());//getContentPane().



    //TABBED PANE
    tabbedPane = new JTabbedPane();
    tabbedPane.setPreferredSize(new Dimension(widthCarMapAndButtons,heightCarMapAndButtons));
    jpnlCarDeckDrawing = new CarsDrawingJpnl(widthCarMapAndButtons,heightCarMapAndButtons);
    jpnlPlatformDeckDrawing = new CarsDrawingJpnl(widthCarMapAndButtons,heightCarMapAndButtons);
    jpnlTrailerDeckDrawing = new CarsDrawingJpnl(widthCarMapAndButtons,heightCarMapAndButtons);


    tabbedPane.add(jpnlCarDeckDrawing);
    Dimension tabbedPaneTabSize= new Dimension(150,30);   
    JLabel labCarDeck = new JLabel("Car Deck");
    labCarDeck.setFont(labCarDeck.getFont().deriveFont (20.0f).deriveFont(Font.PLAIN));

    labCarDeck.setPreferredSize(tabbedPaneTabSize);
    tabbedPane.setTabComponentAt(0, labCarDeck);  // tab index, jLabel


    tabbedPane.add(jpnlPlatformDeckDrawing);
    JLabel labPlatformDeck = new JLabel("Platform Deck");
    labPlatformDeck.setFont(labPlatformDeck.getFont().deriveFont (20.0f).deriveFont(Font.PLAIN));

    labPlatformDeck.setPreferredSize(tabbedPaneTabSize);
    tabbedPane.setTabComponentAt(1, labPlatformDeck);  // tab index, jLabel


    tabbedPane.add(jpnlTrailerDeckDrawing);
    JLabel labTrailerDeck = new JLabel("Trailer Deck");
    labTrailerDeck.setFont(labTrailerDeck.getFont ().deriveFont (20.0f).deriveFont(Font.PLAIN));

    labTrailerDeck.setPreferredSize(tabbedPaneTabSize);
    tabbedPane.setTabComponentAt(2, labTrailerDeck);  // tab index, jLabel


    tabbedPane.setSelectedIndex(2);





    jpnlInputFile = new FileReadAndRunJpnl(widthJpnlFunctions, heightJpnlFunctions);
    //jpnlInputFile.openInputDirectTest();

    //SPLIT BETWEEN MAP AND ALL FUNCTION BELOW
    Border borScrollPane = BorderFactory.createEtchedBorder();

    jSplitPaneMapPlusFunctions= new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    jSplitPaneMapPlusFunctions.setBorder(borScrollPane);
    jSplitPaneMapPlusFunctions.setPreferredSize(new Dimension(widthCarMapAndButtons,heightCarMapAndButtons));
    jSplitPaneMapPlusFunctions.setResizeWeight(0.90);
    jSplitPaneMapPlusFunctions.setDividerSize(5);
    jSplitPaneMapPlusFunctions.add(tabbedPane);
    jSplitPaneMapPlusFunctions.add(jpnlInputFile);









add(jSplitPaneMapPlusFunctions, BorderLayout.CENTER);// getContentPane().


}

类CarsDrawingJpnl是一个JPanel,它包含一个绘图区域(JPanel)和相应的按钮(JPanel)

Class CarsDrawingJpnl:

public class CarsDrawingJpnl extends JPanel {

private CarsDrawingMap jpnlCarsMap;
private CarMapButtons jpnlCarMapCounterButtons;

private JScrollPane carDrawingScroller;
private JSplitPane jSplitPaneMapPlusFunctions;


private TwoJourneyModel twoJourneyCustomers;




public CarsDrawingJpnl(int width , int height) {


    this.setPreferredSize(new Dimension(width,height));//this is neccesary for the component to realize the size in practicality given in constructor
    this.setLayout(new BorderLayout());
    Border borScrollPane = BorderFactory.createEtchedBorder();
    this.setBorder(borScrollPane);
    //CAR MAP

    int widthJpnlMapButtons=width, heightJpnlMapButtons=height/6;

    int widthCarMap=width, heightCarMap = height-heightJpnlMapButtons;
    jpnlCarsMap = new CarsDrawingMap(this,widthCarMap,heightCarMap);

    carDrawingScroller = new JScrollPane( jpnlCarsMap);

    carDrawingScroller.getVerticalScrollBar().setUnitIncrement(5);
    carDrawingScroller.getVerticalScrollBar().setPreferredSize(new Dimension(30,5));
    carDrawingScroller.getHorizontalScrollBar().setUnitIncrement(7);
    carDrawingScroller.getHorizontalScrollBar().setPreferredSize(new Dimension(5,30));
    carDrawingScroller.setBorder(borScrollPane);


    jpnlCarMapCounterButtons= new CarMapButtons(this,widthJpnlMapButtons, heightJpnlMapButtons);
    DisabledPanel.disable(jpnlCarMapCounterButtons);

    //SPLIT BETWEEN MAP AND ALL FUNCTION BELOW
    jSplitPaneMapPlusFunctions= new JSplitPane(JSplitPane.VERTICAL_SPLIT);
//  jSplitPaneMapPlusFunctions.setDividerLocation(0.5);
    jSplitPaneMapPlusFunctions.setResizeWeight(0.70);
    jSplitPaneMapPlusFunctions.setDividerSize(5);
    jSplitPaneMapPlusFunctions.add(carDrawingScroller);
    jSplitPaneMapPlusFunctions.add(jpnlCarMapCounterButtons);


    this.add(jSplitPaneMapPlusFunctions, BorderLayout.CENTER);



}
.
.
.
.
.
.
.
.

当我运行我的主类时,Class CarsDrawingJpnl中使用的分割窗格的大小仅在运行程序开始时的当前选项卡中更新,如下图所示。

运行主JFrame类时的当前选项卡:

https://i.stack.imgur.com/ge6ra.jpg

虽然其他标签不显示JSplitPane的实际重量,而其中三个标签是同一类的对象并以相同的方式实例化。另一个标签可以在下图中看到。

运行主JFrame类时的非当前选项卡:

https://i.stack.imgur.com/GfA8i.jpg

我在运行主类时选择的任何一个标签都会显示更新的重量,而其余的则没有显示。

0 个答案:

没有答案