Java Swing Musings

To prevent window from resizing:

frame.setResizable(false)

 

Manage two radio buttons so that only 1 is selectable at a time:

Use ButtonGroup
ButtonGroup group = new ButtonGroup();
group.add(birdButton);
group.add(catButton);

 

In my application I have move the user from one screen to next on button click. I am wondering how to do it in Swing. There are couple of good posts I have come across for this Post1, Post2.

97kgp

 

Adding Border around a container: Set an EmptyBorder around your JPanel.

JPanel p =new JPanel();
p.setBorder(new EmptyBorder(10, 10, 10, 10));

OR

JPanel containerPanel = new JPanel();
containerPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
containerPanel.setLayout(new BorderLayout());

 

Setting a background color same as container color

list.setBackground(panel.getBackground());

 

Anytime we modify the GUI in Swing we need to call:

frame.revalidate()
frame.repaint()


Why use of multiple JFrames in a Swing Application is a bad practice: Post

 

Right now I am searching how to update a JList with some contents, I wud be fetching from remote server.

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s