Netbeans api has bug, the west slidebar not always align to top

Netbeans api has bug, the west slidebar not always align to top, here my layout.xml

		<folder name="SideBar">
			<file name="com-pdk-sidebar-AddressSideBarFactory.instance">
				<attr name="position" intvalue="0"/>
				<attr name="location" stringvalue="West"/>
				<attr name="scrollable" boolvalue="true"/>
			</file>
		</folder>

package com.pdk.sidebar;

import com.pdk.NetbeansUtil;
import com.pdk.ToggleAddressSideBarAction;
import com.peterdwarf.dwarf.Dwarf;
import com.peterdwarf.dwarf.DwarfLib;
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Vector;
import javax.swing.JComponent;
import javax.swing.text.JTextComponent;
import org.netbeans.api.project.Project;
import org.openide.loaders.DataObject;
import org.openide.util.Lookup;
import org.openide.util.Utilities;

public class AddressSideBarFactory implements org.netbeans.spi.editor.SideBarFactory {

	public static ArrayList<AddressPanel> addressPanels = new ArrayList<AddressPanel>();
	public static AddressPanel addressPanel;

	@Override
	public JComponent createSideBar(JTextComponent jtc) {
		AddressSideBarFactory.addressPanel = new AddressPanel(jtc);
		addressPanels.add(addressPanel);
		addressPanel.setOpaque(false);
		addressPanel.setVisible(ToggleAddressSideBarAction.visible);
		int width = jtc.getFontMetrics(jtc.getFont()).stringWidth("00000000");
		addressPanel.setPreferredSize(new Dimension(width, 10));
		Project project = NetbeansUtil.getProject();
		if (project != null) {
			if (!project.getProjectDirectory().getName().toLowerCase().equals("peteri")) {
				return null;
			}
			Lookup context = Utilities.actionsGlobalContext();
			DataObject file = context.lookup(DataObject.class);
			if (file != null) {
				//File dir = new File(file.getFolder().getPrimaryFile().getPath());

				File fileObj = new File(file.getPrimaryFile().getPath());
				String filename = fileObj.getName().toLowerCase();
				if (filename.endsWith(".c") || filename.endsWith(".cpp") || filename.endsWith(".cc") || filename.endsWith(".s") || filename.endsWith(".asm")) {
//					jtc.addCaretListener(new CaretListener() {
//						@Override
//						public void caretUpdate(CaretEvent e) {
//							addressPanel.repaint();
//						}
//					});

					jtc.addMouseListener(new MouseListener() {
						@Override
						public void mouseClicked(MouseEvent e) {

						}

						@Override
						public void mousePressed(MouseEvent e) {
							addressPanel.repaint();
						}

						@Override
						public void mouseReleased(MouseEvent e) {

						}

						@Override
						public void mouseEntered(MouseEvent e) {

						}

						@Override
						public void mouseExited(MouseEvent e) {

						}
					});
					Vector<Dwarf> dwarfVector = DwarfLib.init(new File("/Users/peter/workspace/PeterI/kernel/kernel"), 0, false);
					Hashtable<Integer, BigInteger> ht = DwarfLib.getAddresses(dwarfVector, fileObj.getName());
					addressPanel.lineInfo = ht;
				} else {
					return null;
				}
			}

		}

		return addressPanel;
	}
}
package com.pdk.sidebar;

import com.pdk.ModuleLib;
import com.pdk.ToggleAddressSideBarAction;
import com.peterswing.CommonLib;
import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.RenderingHints;
import java.math.BigInteger;
import java.util.Hashtable;
import javax.swing.JPanel;
import javax.swing.plaf.TextUI;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.JTextComponent;
import javax.swing.text.Position;
import javax.swing.text.StyledDocument;
import javax.swing.text.View;
import org.netbeans.api.editor.mimelookup.MimeLookup;
import org.netbeans.api.editor.mimelookup.MimePath;
import org.netbeans.api.editor.settings.FontColorNames;
import org.netbeans.api.editor.settings.FontColorSettings;
import org.netbeans.editor.BaseTextUI;
import org.netbeans.editor.Coloring;
import org.netbeans.editor.Utilities;
import org.openide.text.NbDocument;

public class AddressPanel extends JPanel {

	private final JTextComponent jtc;
	Hashtable<Integer, BigInteger> lineInfo;
	TextUI textUI;
	View rootView;
	Color backgroundColor = Color.decode("#eaeaea");

	AddressPanel(JTextComponent jtc) {
		this.jtc = jtc;

		textUI = jtc.getUI();
		rootView = Utilities.getDocumentView(jtc);
	}

	@Override
	public void paint(final Graphics g) {
		if (!ToggleAddressSideBarAction.visible) {
			return;
		}
		super.paint(g);
//		ModuleLib.log(this.getParent());
//		ModuleLib.log(this.getParent().getParent());
		((Graphics2D) g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
		g.setFont(jtc.getFont());
		g.setColor(backgroundColor);
		g.fillRect(0, 0, getWidth(), getHeight());

		Document document = jtc.getDocument();
		//HighlightsContainer hc = HighlightingManager.getInstance(jtc).getBottomHighlights();
		//HighlightsSequence hq = hc.getHighlights(0, document.getLength());

		FontMetrics metrics = g.getFontMetrics(jtc.getFont());
		int fontHeight = metrics.getHeight();

		int lineNo = document.getDefaultRootElement().getElementIndex(jtc.getCaretPosition());
		//ModuleLib.log("lineNo=" + lineNo + ", " + fontHeight);
		FontColorSettings fcs = MimeLookup.getLookup(MimePath.EMPTY).lookup(FontColorSettings.class);
		Coloring c = Coloring.fromAttributeSet(fcs.getFontColors(FontColorNames.CARET_ROW_COLORING));
		g.setColor(c.getBackColor());
		g.fillRect(0, fontHeight * lineNo, getWidth(), fontHeight);

		if (lineInfo != null) {
			try {
				if (rootView == null) {
					return;
				}
				int startPos = getPosFromY(jtc, textUI, 0);
				int startViewIndex = rootView.getViewIndex(startPos, Position.Bias.Forward);
				int rootViewCount = rootView.getViewCount();

				if (startViewIndex >= 0 && startViewIndex < rootViewCount) {
					g.setColor(Color.gray);
					int y = 0;
					for (int i = startViewIndex; i < rootViewCount; i++) {
						View view = rootView.getView(i);
						if (view == null) {
							break;
						}
						lineNo = NbDocument.findLineNumber((StyledDocument) document, view.getStartOffset());

						//g.drawString(String.valueOf(lineNo + 1), 0, (StyleConstants.getFontSize(as) + 5) * lineNo + 14);
						//int firstMargin = (fontHeight - StyleConstants.getFontSize(as)) / 2;
						BigInteger address = lineInfo.get(lineNo + 1);
						//ModuleLib.log(lineInfo + " = " + String.format("%08X", address));
						if (address != null) {
							g.drawString(String.format("%08X", address), 0, fontHeight * (y + 1) - 3);
						}
						y++;
						//ModuleLib.log("lineNo=" + lineNo);
					}
				}
			} catch (Exception ex) {
				ModuleLib.log(CommonLib.printException(ex));
			}
		}
	}

	private int getPosFromY(JTextComponent component, TextUI textUI, int y) throws BadLocationException {
		if (textUI instanceof BaseTextUI) {
			return ((BaseTextUI) textUI).getPosFromY(y);
		} else {
			// fallback to ( less otimized than ((BaseTextUI) textUI).getPosFromY(y) )
			return textUI.modelToView(component, textUI.viewToModel(component, new Point(0, y))).y;
		}
	}
}

read count : 29