请问这个布局应该如何实现?
左边的“主角能否通过”是一个文字说明,不可以点击,只是起到一个说明的作用,具体的功能需要通过右边的下拉框选择。

解决方案 »

  1.   

    BorderLayout 布局管理器吧..不知有没正确理解楼主的意思?
      

  2.   


    就是说行分成两部分,左边一半是文字说明,右边一般是一个下拉列表,用户可以在右边的下拉列表中选择。BorderLayout我试了,实现这种功能不知道怎么弄。难道把左边添加一个Panel,然后add(new Label("主角能否通过")) ,然后在右边在添加JComboBox
    这样来做么?
      

  3.   

    LZ尝试过自定义布局吗?用JPanel也没错啊,你可以先都new出来。但是要设置setvisible(false),通过了就设置为true嘛、
      

  4.   


            Panel passPanel = new Panel(new BorderLayout()) ;
            Panel passPanel1= new Panel() ;
            passPanel1.add(new Label("主角能否通过")) ;
            passPanel.add(passPanel1,"West") ;
            String num[] = {"通过","不能通过","状态1","状态2","...",} ;
            JComboBox choiceBox = new JComboBox(num) ;
            choiceBox.setEnabled(true);
            choiceBox.setEditable(true);
            passPanel.add(choiceBox,"East") ;
            sysFuncPanel.add(passPanel) ;
            
    function.add(sysFuncPanel) ;
            function.setVisible(true);
    刚才试了一下,以上的代码确实能实现上面的效果,但是最终界面中,"主角能否通过"这行提示占用了太宽的显示宽度,看起来很不雅观,请问这该怎么办? 
      

  5.   


            Panel passPanel = new Panel(new BorderLayout()) ;
            Panel passPanel1= new Panel() ;
            passPanel1.add(new Label("主角能否通过")) ;
            passPanel.add(passPanel1,"West") ;
            String num[] = {"通过","不能通过","状态1","状态2","...",} ;
            JComboBox choiceBox = new JComboBox(num) ;
            choiceBox.setEnabled(true);
            choiceBox.setEditable(true);
            passPanel.add(choiceBox,"East") ;
            sysFuncPanel.add(passPanel) ;
            
    function.add(sysFuncPanel) ;
            function.setVisible(true);
    刚才试了一下,以上的代码确实能实现上面的效果,但是最终界面中,"主角能否通过"这行提示占用了太宽的显示宽度,看起来很不雅观,请问这该怎么办? 
      

  6.   

    答:GUI布局我最拿手,可就是看不到图!右键点一下显示图片还是没有用啊。有点儿急...,但无奈中....
      

  7.   


    这个好办啊,使用嵌套的Border和GridLayout来进行布局有点死板。有个高难度的GridBagLayout。
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class GridBagWindow extends JFrame {
      private JButton searchBtn;
      private JComboBox modeCombo;
      private JLabel tagLbl;
      private JLabel tagModeLbl;
      private JLabel previewLbl;
      private JTable resTable;
      private JTextField tagTxt;
     public GridBagWindow() {
       Container contentPane = getContentPane();
       GridBagLayout gridbag = new GridBagLayout();
       contentPane.setLayout(gridbag);
       GridBagConstraints c = new GridBagConstraints();
       //setting a default constraint value
       c.fill =GridBagConstraints.HORIZONTAL;
       tagLbl = new JLabel("Tags");
       c.gridx = 0; //x grid position
       c.gridy = 0; //y grid position
       gridbag.setConstraints(tagLbl, c); //associate the label with a constraint object 
       contentPane.add(tagLbl); //add it to content pane
       
       tagModeLbl = new JLabel("Tag Mode");
       c.gridx = 0;
       c.gridy = 1;
       gridbag.setConstraints(tagModeLbl, c);
       contentPane.add(tagModeLbl);
       tagTxt = new JTextField("plinth");
       c.gridx = 1;
       c.gridy = 0;
       c.gridwidth = 2;
       gridbag.setConstraints(tagTxt, c);
       contentPane.add(tagTxt);
       String[] options = {"all", "any"};
       modeCombo = new JComboBox(options);
       c.gridx = 1;
       c.gridy = 1;
       c.gridwidth = 1;
       gridbag.setConstraints(modeCombo, c);
       contentPane.add(modeCombo);
       searchBtn = new JButton("Search");
       c.gridx = 1;
       c.gridy = 2;
       gridbag.setConstraints(searchBtn, c);
       contentPane.add(searchBtn);
       resTable = new JTable(5,3);
       c.gridx = 0;
       c.gridy = 3;
       c.gridwidth = 3;
       gridbag.setConstraints(resTable, c);
       contentPane.add(resTable);
       previewLbl = new JLabel("Preview goes here");
       c.gridx = 0;
       c.gridy = 4;
       gridbag.setConstraints(previewLbl, c);
       contentPane.add(previewLbl);
      addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
         System.exit(0);
        }
      });
    }
     public static void main(String args[]) {
      GridBagWindow window = new GridBagWindow();
      window.setTitle("GridBagWindow");
      window.pack();
      window.setVisible(true);
     }
    }
      

  8.   


    public class TestFrame2 extends JFrame {
    public TestFrame2(){
    super();
    this.setTitle("test frame");
    this.setSize(500, 500);
    JLabel title = new JLabel("主角能否通过");
    title.setBorder(BorderFactory.createLineBorder(Color.BLACK));
    title.setHorizontalAlignment(SwingConstants.CENTER);
    String[] items = {"1", "2", "3"};
    JComboBox list = new JComboBox(items); 
    JPanel panel = new JPanel();               
    panel.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weightx = 0.2;
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridwidth = 1;
    panel.add(title, gbc);
    gbc.weightx = 0.8;
    gbc.gridx = 1;
    panel.add(list, gbc);

    getContentPane().add(panel, BorderLayout.CENTER);

    }
      

  9.   

    你可以到这个地址去看
    http://photo.sina.com.cn/u/1132553125
    第一张就是