Current location - Loan Platform Complete Network - Big data management - Why can't the buttons and other controls added by java myeclipse on the panel be displayed?
Why can't the buttons and other controls added by java myeclipse on the panel be displayed?
Problems with the swing layout in myeclipse prevent the control from being displayed.

Examples are as follows:

Import? Java . awt . event queue;

Import? Java . awt . flow layout;

Import? javax . swing . image icon;

Import? javax . swing . jbutton;

Import? javax . swing . jframe;

Import? javax . swing . jpanel;

Import? javax . swing . ui manager;

Import? javax . swing . border . empty border;

Public? Class? JButtonDemo? Extension? JFrame? {

Private? Static electricity Final? Dragon? serialVersionUID? =? 865 175526 1675396406 l;

Private? JPanel? contentPane

Public? Static electricity Invalid? main(String[]? args)? {

Try it? {

UIManager

. setLookAndFeel(" com . sun . Java . swing . plaf . nimbus . nimbus lookandfeel ");

}? Catch? (Can you throw it? e)? {

e . printstacktrace();

}

EventQueue.invokeLater (new? Runnable()? {

Public? Invalid? run()? {

Try it? {

JButtonDemo? Frame? =? New? JButtonDemo();

frame . set visible(true);

}? Catch? (exception? e)? {

e . printstacktrace();

}

}

});

}

Public? JButtonDemo()? {

SetTitle ("button use"); //? Set the title of the form.

setDefaultCloseOperation(JFrame。 EXIT _ ON _ CLOSE); //? Set the action when the form exits.

setBounds( 100,? 100,? 250,? 100); //? Set the position and size of the form.

contentPane? =? New? JPanel(); //? Create content panel

ContentPane.setBorder (new? EmptyBorder(5,5,? 5,? 5)); //? Set the border of the panel.

SetContentPane; //? Application content panel

ContentPane.setLayout (new? Process layout (process layout. Center,? 5,? 5)); //? Set the content panel to flow layout.

JButton? modifyButton? =? New? JButton ("modification"); //? Create button

ModifyButton.setIcon (new? ImageIcon(JButtonDemo.class

. get resource("/images/modify . gif ")); //? Add an icon to a button

content pane . add(modify button); //? Add a button to a panel

JButton? Delete button? =? New? JButton(" delete "); //? Create button

DeleteButton.setIcon (new? ImageIcon(JButtonDemo.class

. get resource("/images/delete . gif ")); //? Add an icon to a button

content pane . add(delete button); //? Add a button to a panel

}

}

Operation effect: