This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
I have added a JButton to a JPanel then added that JPanel to the South part of a boarderlayout. My button runs the entire length of my borderlayout. I have tried setPreferredSize() and it does change the height of the button but the length is still the same. I need to make the length of the button smaller. Any ideas? Thanks,
It sounds like you're on the right track. What layout manager are you using for your JPanel? It sounds like you're using BorderLayout. BorderLayout respects the preferred height for the north and south components, but always stretches them to the edges of the container. The default for JPanel is FlowLayout, which is probably what you want to use here. It is one of the few layout managers that actually respects both dimensions of preferred sizes. Here's some code for you. It creates a JButton and displays it in the south panel according to its preferred size. Of course, this code needs more, including a way to shut down the application, but it should get you off to a good start. Good luck! Pete Boton JFastTrack.com