Eclipse plug-in development learning note "7"---add preferences

Source: Internet
Author: User

Eclipse plug-in development learning note "7"---add preferences

First, we create a new plug-in project, Open the Plugin.xml file Select the Extensions tab, add a org.eclipse.ui.preferencePages extension point, and add a page as shown in the figure, and note that the category of the second page is the ID of the first page.

Right-click the SRC folder to create a new class, create 2 classes for Page1,page2, inherit the Preferencepage class, and implement the Iworkbenchpreferencepage interface.

/**

*

* Page1

*

*/

Package addpreferencepage.pages;

Import Org.eclipse.jface.preference.PreferencePage;

Import Org.eclipse.swt.SWT;

Import Org.eclipse.swt.layout.FillLayout;

Import Org.eclipse.swt.widgets.Composite;

Import Org.eclipse.swt.widgets.Control;

Import Org.eclipse.swt.widgets.Label;

Import Org.eclipse.ui.IWorkbench;

Import Org.eclipse.ui.IWorkbenchPreferencePage;

public class Page1 extends Preferencepage implements Iworkbenchpreferencepage {

@Override

public void Init (Iworkbench workbench) {}

@Override

Protected Control createcontents (Composite parent) {

Composite topcom = new Composite (parent, SWT. NONE);

Topcom.setlayout (New Filllayout ());

New Label (topcom, SWT. NONE). SetText ("Welcome to the Custom preferences!) ");

return topcom;

}

}

/**

*

* Page2

*

*/

Package addpreferencepage.pages;

Import Org.eclipse.jface.preference.PreferencePage;

Import Org.eclipse.swt.SWT;

Import Org.eclipse.swt.layout.FillLayout;

Import Org.eclipse.swt.widgets.Composite;

Import Org.eclipse.swt.widgets.Control;

Import Org.eclipse.swt.widgets.Label;

Import Org.eclipse.ui.IWorkbench;

Import Org.eclipse.ui.IWorkbenchPreferencePage;

public class Page2 extends Preferencepage implements Iworkbenchpreferencepage {

@Override

public void Init (Iworkbench workbench) {}

@Override

Protected Control createcontents (Composite parent) {

Composite topcom = new Composite (parent, SWT. NONE);

Topcom.setlayout (New Filllayout ());

New Label (topcom, SWT. NONE). SetText ("Sub-option! ");

return topcom;

}

}

Click Run, Effect

Eclipse plug-in development learning note "7"---add preferences

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.