Nails (brads) will work as they will allow a little bit of movement. The best way I know of, especially if you have a large panel that will move a lot, would be dovetailed buttons. Cut a dovetailed groove in the back of your trim. Cut matching dovetailed keys out of some stock. Cross cut them to short lengths, about 3". Drill and counter sink screw holes in the keys and attach them to the edge of your panel with screws. One at each end and one/two in the middle. Slide your trim over those keys and glue the mitered corners. That will allow the panel to move and keep the trim tight to the ends of the panel. The long grain trim can just be glued in place.
Here, hopefully, is a little illustration of good methods to use. The dovetailed key is at the bottom. The "screw in an elongated hole from inside the carcass" is another good method if you have the clearance to do it.