How do I get barrels pre-loaded with items in creative mode?

In creative mode, when pressing ctrl + the middle mouse button (mouse wheel), you will get a copy of the item you are looking at with its NBT content. This is vanilla Minecraft. You can then just place that item wherever you want and its original content will be cloned.

That way you can clone :

  • Containers with their contents (chests, barrels, furnaces...)
  • Command Blocks with their command and state
  • Signs with the text written on it (placing it will not prompt the text)
  • Other block entities listed there https://minecraft.gamepedia.com/Block_entity