在没有frame.setJMenuBar的JPanel中显示JMenu

时间:2017-10-06 11:43:26

标签: java swing jpanel jmenubar astah

我想将JMenuBar添加到Jpanel。我试过了:

 p.add(menubar, BorderLayout.NORTH);

另外:我不想在JFrame上使用JSetMenu方法,因为我现在正在制作一个Astah插件,我希望Jpanel(Jmenubar所在的位置)在Astah。

如何将JMenuBar设置为Jpanel以使其位于顶部? 我想将所有内容都放在Jpanel中并将其放入Astah。

将它放入Astah的代码:

import com.change_vision.jude.api.inf.project.ProjectAccessor;
import com.change_vision.jude.api.inf.project.ProjectAccessorFactory;
import com.change_vision.jude.api.inf.project.ProjectEvent;
import com.change_vision.jude.api.inf.project.ProjectEventListener;
import com.change_vision.jude.api.inf.ui.IPluginExtraTabView;
import com.change_vision.jude.api.inf.ui.ISelectionListener;

import javax.swing.*;
import java.awt.*;

public class showobjects extends JPanel implements IPluginExtraTabView, ProjectEventListener {
public showobjects () {
    initComponents();
}

private void initComponents() {
    setLayout(new BorderLayout());
    add(createLabelPane());
    addProjectEventListener();
}

private void addProjectEventListener() {
    try {
        ProjectAccessor projectAccessor = ProjectAccessorFactory.getProjectAccessor();
        projectAccessor.addProjectEventListener(this);
    } catch (ClassNotFoundException e) {
        e.getMessage();
    }
}

private Container createLabelPane() {
    JLabel label = new JLabel("showobjects ");
    JScrollPane pane = new JScrollPane(label);

    showobjects  app = new showobjects ();
    JPanel mainJpanel  = app.createJPanel();


    return mainJpanel;
}

@Override
public void projectChanged(ProjectEvent e) {
}

@Override
public void projectClosed(ProjectEvent e) {
}

@Override
public void projectOpened(ProjectEvent e) {
}

@Override
public void addSelectionListener(ISelectionListener listener) {
}

@Override
public Component getComponent() {
    return this;
}

@Override
public String getDescription() {
    return "Show showobjects  here";
}

@Override
public String getTitle() {
    return "showobjects ";
}

public void activated() {

}

public void deactivated() {

}
}

1 个答案:

答案 0 :(得分:1)

我做了一个非常简单的测试,它很好用。根据我可以从您的代码中推断出的内容,您正在使用...

app.service('StoreService',['$http', function ($http,$q) {

    this.runQuery = function runQuery(statement){
        return $http({
          method: 'GET',
          url: 'http://localhost:8080/runQuery/',
          params: {statement:statement},
          headers: 'Accept:application/json'
        }).then( function(response){
            ̶r̶e̶t̶u̶r̶n̶ ̶ ̶r̶e̶p̶o̶n̶s̶e̶.̶d̶a̶t̶a̶;̶
            return response.data
        });
    }
 }]);

会将mainJPanel.add(AuguSoftModellerobjectsNew.createMenuBar()); 放置在面板的JMenuBar(或默认)位置,该位置将被您添加的其他组件隐藏

CENTRE