You can use GridBagLayout for this. Here is a sample that shows two buttons - one maintains its width and the other one changes its width when the frame is resized.
Note the GridBagConstraints that tell the component how it should behave in the layout. The weight controls the resize behaviour. Further information can be found in the Java Tutorials.
package test;
import java.awt.Button;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JFrame;
public class LayoutResizeButtonTest extends JFrame {
public static void main(String[] args) {
LayoutResizeButtonTest app = new LayoutResizeButtonTest();
app.setDefaultCloseOperation(EXIT_ON_CLOSE);
app.setVisible(true);
}
LayoutResizeButtonTest() {
this.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 1.0;
this.add(new Button("Resizable"), c);
c = new GridBagConstraints();
c.weightx = 0.0;
this.add(new Button("Not Resizable"));
this.pack();
}
}