@Override
		public void mouseDragged(MouseEvent e) {
			if (!selectionActive || e.isConsumed()) {
				return;
			}

			e.consume();

			Point p = e.getPoint();

			if (p.x == lastX) {
				return;
			}
			Cursor cursor = Cursor.getPredefinedCursor(
				p.x < lastX ? Cursor.W_RESIZE_CURSOR : Cursor.E_RESIZE_CURSOR);
			setCursor(cursor);
			lastX = p.x;

			int bitOffset = placementComponent.getBitOffset(p);
			if (bitOffset == lastBit) {
				return;
			}

			// ensure that scroll region keeps mouse point visible
			if (!placementComponent.getVisibleRect().contains(p)) {
				BitAttributes bitAttributes = placementComponent.getBitAttributes(e.getPoint());
				if (bitAttributes != null) {
					placementComponent.scrollRectToVisible(bitAttributes.getRectangle());
				}
			}

			if (bitOffset >= 0) {
				// NOTE: spinner models require use of long values
				lastBit = bitOffset;
				if (bitOffset <= startBit) {
					int start = Math.min(startBit, bitOffset);
					bitOffsetModel.setValue((long) start);
				}
				long bitSize = Math.abs(bitOffset - startBit) + 1;
				bitSizeModel.setValue(bitSize);
			}
		}
<code>BitFieldEditorPanel</code> provides the ability to add or modify bitfields
within non-packed structures.
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/BitFieldEditorPanel.java