首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用setAlignmentX在Scala MainFrame中对齐按钮

使用setAlignmentX在Scala MainFrame中对齐按钮
EN

Stack Overflow用户
提问于 2013-10-27 06:54:37
回答 1查看 163关注 0票数 0

我在一个简单的Scala MainFrame图形用户界面上遇到了让按钮居中对齐的问题。我已经尝试了许多buttonname.peer.setAlignmentX和Y的组合,但都没有效果。

代码如下所示:

代码语言:javascript
复制
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会有用法的例子吗?

EN

回答 1

Stack Overflow用户

发布于 2013-10-27 08:58:21

在研究了post Scala Swing组件对齐之后,我能够使用BorderPanel {}来定位按钮,如以下代码所示:

代码语言:javascript
复制
// 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   ***** 

在发我的帖子之前应该先看一下。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19612766

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档