如何在Eclipse / Java / WindowsBuilder中查看自定义组件 [英] How do I view custom components in Eclipse/Java/WindowsBuilder

查看:151
本文介绍了如何在Eclipse / Java / WindowsBuilder中查看自定义组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,



所以说你在WindowsBuilder中设计一个ApplicationWindow,你可以通过将你的类扩展到JPanel来创建自己的JPanel。如何在Eclipse / JavaEE / WindowsBuilder中获取Design选项卡以显示您刚刚创建的自定义组件?



默认情况下,在我的机器上,至少,它隐藏了。我看不到它。



有什么地方可以看到吗?



谢谢,

解决方案

看来如果你为你的gui声明你的自定义组件(这里是JPanel)主类的OUTSIDE,就像这样:



  package  views; 

import java.awt.EventQueue;
...

// --------- -------------------------------------------------- ---------------- //
// 这是我的子类jpanel,用于绘制声明的OUTSIDE主要的gui类。

class MyJPanel extends JPanel
{
@ Override
public void paintComponent(Graphics g)
{
super .paintComponent (G);
}
}

// ------ -------------------------------------------------- ------------------- //



// 这是gui的主要类
public class SandboxToo
{
private JFrame框架;
private JPanel面板;
private MyJPanel myPanel;
...





然后您的自定义组件将在UI中正确显示。

< br $> b $ b



但是,如果你宣告你的自定义类INSIDE你的gui的主要类...

< pre lang =java> package views;

import java.awt.EventQueue;

public class SandboxToo / / 这是gui的主类
{
// 现在我的自定义JPanel被声明为INSID主要的gui类
class MyJPanel extends JPanel
{
@ Override
public void paintComponent(Graphics g)
{
super .paintComponent(克);
}
}
私人 JFrame框架;
private JPanel面板;
私人 MyJPanel myPanel;





...然后你的自定义组件出现在设计器中。





此外,将子类的位置从内部更改为主类的外部实际上需要您保存并关闭选项卡并重新打开WindowsBuilder的选项卡可以自行重置并正确显示。这是一个错误。



这显然需要你的代码限制,所以你去,祝你好运! :)


Greetings,

So say you are designing an ApplicationWindow in WindowsBuilder and you create your own JPanel by extending your class to a JPanel. How do you get the Design tab in Eclipse/JavaEE/WindowsBuilder to show that custom component you just created?

By default, on my machine, at least, its hidden. I can't see it.

Is there a setting somewhere to see it?

Thanks,

解决方案

It appears that if you declare your custom component (JPanel here) OUTSIDE of the main class for your gui, like so:

package views;

import java.awt.EventQueue;
...

//---------------------------------------------------------------------------//
//This is my subclassed jpanel for drawing declared OUTSIDE the main gui class.

class MyJPanel extends JPanel
{
    @Override
    public void paintComponent(Graphics g) 
    {
       super.paintComponent(g);
    }	
}

//---------------------------------------------------------------------------//



//This is the main class for the gui
public class SandboxToo 
{
	private JFrame frame;
	private JPanel panel;
	private MyJPanel myPanel;
	...



Then your custom component will show up properly in the UI.



However, if you declare your custom class INSIDE the main class of your gui...

package views;

import java.awt.EventQueue;

public class SandboxToo //This is the main class for the gui
{
        // Now my custom JPanel is declared INSIDE the main gui class
	class MyJPanel extends JPanel
	{
	    @Override
	    public void paintComponent(Graphics g) 
	    {
	       super.paintComponent(g);
	    }	
	}	
	private JFrame frame;
	private JPanel panel;
	private MyJPanel myPanel;



...then your custom component show up in the designer.


Moreover, changing the location of your subclass from inside to outside the main class will actually require you to save and close the tab and reopen the tab for WindowsBuilder to reset itself and display properly. This is sort of a bug.

This entails limitations in your code, obviously, so there you go, good luck! :)


这篇关于如何在Eclipse / Java / WindowsBuilder中查看自定义组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆