【问题标题】:Aligning buttons in a Scala MainFrame using setAlignmentX使用 setAlignmentX 对齐 Scala MainFrame 中的按钮
【发布时间】:2013-10-26 22:54:37
【问题描述】:

我无法让简单的 Scala MainFrame GUI 上的按钮居中对齐。 尝试了很多buttonname.peer.setAlignmentX和Y的组合都没有效果。

代码如下:

object CGui extends SimpleSwingApplication 
   {
     def top = new MainFrame 
      {
        title = "Client Dashboard"
        var tbox    = new TextArea(4,20) { text = "Welcome to the dashboard"}
        val stats_button = new Button    { text = " View Statistics    " }
        val sp_button = new Button       { text = " Add Server Process " }
        val cp_button = new Button       { text = " Add Local Process  " } 
        val conn_button = new Button     { text = " Connect" } 
        val quit_button = new Button     { text = " Quit" }
  // GUI Components *************************************************End   *****
  // GUI SetUp ******************************************************Start *****
        contents = new BoxPanel(Orientation.Vertical) 
         {
           contents += new Label("            ")
           contents += tbox
           contents += new Label("            ")
           contents += stats_button
           contents += new Label("            ")
           contents += sp_button
           contents += new Label("            ")
           contents += cp_button
           contents += new Label("            ")
           contents += new FlowPanel {
           contents += new Label("            ")
           contents += conn_button
           contents += quit_button }
           border = Swing.EmptyBorder(20, 20, 20, 20)
         }
        listenTo(sp_button, cp_button, stats_button, conn_button, quit_button)
  // GUI SetUp ******************************************************End   ***** 

谁能指出我对 setAlignmentX,Y 用法的任何描述。 ScalaDoc 有使用示例吗?

【问题讨论】:

    标签: scala-swing


    【解决方案1】:

    在调查了 Scala Swing 组件对齐后,我能够使用 BorderPanel { } 按以下代码定位按钮:

    // GUI SetUp ******************************************************Start *****
            contents = new BoxPanel(Orientation.Vertical) 
             {
               contents += new Label("            ")
               contents += tbox
               contents += new Label("            ")
               contents += new BorderPanel {
                add(stats_button, BorderPanel.Position.Center)}
               contents += new Label("            ")
               contents += new BorderPanel {
                add(sp_button, BorderPanel.Position.Center)}
               contents += new Label("            ")
               contents += new BorderPanel {
                add(cp_button, BorderPanel.Position.Center)}
               contents += new Label("            ")
               contents += new FlowPanel 
               {
                contents += new BorderPanel {
                add(conn_button, BorderPanel.Position.West)
                add(quit_button, BorderPanel.Position.Center) }
               }
    
               border = Swing.EmptyBorder(20, 20, 20, 20)
             }
            listenTo(sp_button, cp_button, stats_button, conn_button, quit_button)
      // GUI SetUp ******************************************************End   ***** 
    

    在发我之前应该看看它。

    【讨论】:

      猜你喜欢
      • 2014-03-15
      • 2016-03-30
      • 2012-06-23
      • 1970-01-01
      • 2013-04-11
      • 1970-01-01
      • 1970-01-01
      • 2015-06-04
      • 1970-01-01
      相关资源
      最近更新 更多