想用swing做一个比较漂亮的增加用户/修改用户的界面。需要增加的属性就我自己定了。

解决方案 »

  1.   

      觉得java自身不擅长于编写界面。在没有美工支持下,更难做出漂亮的界面。
      布局做出来美观整洁就不错了。
      

  2.   

    ls 定义的是界面风格。  
    整体的布局还是自己写写吧。只有自己才知道想要怎么样的效果。
    如果不会使用布局管理器,就将布局管理器设置为null,然后自己设置组件的大小和位置。
    可以使用netbean或者jbuilder进行swing界面的编写,因为可以直接拖动组件会比较方便。
      

  3.   

    SWING很难做漂亮的!用setLookAndFeel方法是可行的!
    用SWT/JFACE吧!!!!!!!
      

  4.   

    想好看,用用swing的ui框架,例如swingX等等 
      

  5.   

    myeclipse中有swing的图形编辑窗口,编辑好直接有代码。。
      

  6.   

    O'Reilly:Java Swing(第二版)Java Swing,Second Edition   
      

  7.   

    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.Graphics;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Image;
    import java.awt.Insets;
    import java.io.File;import javax.imageio.ImageIO;
    import javax.swing.BorderFactory;
    import javax.swing.Box;
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;public class UserDialog extends JFrame{
    private JLabel nameLbl = new JLabel("Name:");
    private JLabel passwordLbl = new JLabel("Password:");
    private JLabel confirmPwdLbl = new JLabel("Confirm Password:");
    private JTextField nameField = new JTextField();
    private JTextField passwordField = new JTextField();
    private JTextField confirmPwdField = new JTextField();
    private JButton confirmBtn = new JButton("Confirm");
    private JButton cancelBtn = new JButton("Cancel");


    public UserDialog(String title){
    super(title);
    initComponents();
    }
    public void initComponents(){
    Image backgroundImage = null;
    try{
    backgroundImage = ImageIO.read(new File(""));
    }catch(Exception ex){

    }
    JPanel mainPanel = new BackgroundPanel(backgroundImage);

    Color backgroundColor = this.getBackground();


    mainPanel.setBackground(backgroundColor);
    mainPanel.setLayout(new BorderLayout());
    mainPanel.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
    GridBagLayout gridBagLayout = new GridBagLayout();
    GridBagConstraints constraints = new GridBagConstraints();
    JPanel centerPanel = new JPanel();
    centerPanel.setBackground(backgroundColor);
    centerPanel.setLayout(gridBagLayout);
    centerPanel.setBorder(BorderFactory.createEmptyBorder(5,10,5,5));
    constraints.fill = GridBagConstraints.BOTH;
    constraints.insets = new Insets(5,10,5,5);
    gridBagLayout.setConstraints(nameLbl, constraints);
    centerPanel.add(nameLbl);
    constraints.weightx = 1.0;
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagLayout.setConstraints(nameField, constraints);
    centerPanel.add(nameField);
    constraints.gridwidth = GridBagConstraints.RELATIVE;
    constraints.weightx = 0.0;
    gridBagLayout.setConstraints(passwordLbl, constraints);
    centerPanel.add(passwordLbl);
    constraints.weightx = 1.0;
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagLayout.setConstraints(passwordField, constraints);
    centerPanel.add(passwordField);
    constraints.gridwidth = GridBagConstraints.RELATIVE;
    constraints.weightx = 0.0;
    gridBagLayout.setConstraints(confirmPwdLbl, constraints);
    centerPanel.add(confirmPwdLbl);
    constraints.weightx = 1.0;
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagLayout.setConstraints(confirmPwdField, constraints);
    centerPanel.add(confirmPwdField);
    mainPanel.add(centerPanel,BorderLayout.CENTER);
    JPanel southPanel = new JPanel();
    southPanel.setBackground(backgroundColor);
    southPanel.setLayout(new FlowLayout(FlowLayout.CENTER,0,0));
    southPanel.setBorder(BorderFactory.createEmptyBorder(5,10,20,10));
    southPanel.add(confirmBtn);
    southPanel.add(Box.createHorizontalStrut(30));
    southPanel.add(cancelBtn);
    mainPanel.add(southPanel,BorderLayout.SOUTH);
    Container c = this.getContentPane();
    c.setLayout(new BorderLayout());
    c.add(mainPanel,BorderLayout.CENTER);

    }
    class BackgroundPanel extends JPanel{
    private Image backgroundImage;
    public BackgroundPanel(Image image){
    this.backgroundImage = image;
    }
    public void paintComponent(Graphics g){
    int w = this.getWidth();
    int h = this.getHeight();
    g.setColor(this.getBackground());
    g.fillRect(0, 0, w, h);
    if(backgroundImage != null){
    g.drawImage(backgroundImage, 0, 0, w, h, null);
    }
    }
    }
    public static void main(String[] args){
    JFrame userDialog = new UserDialog("User Dialog");
    userDialog.setBounds(200, 100, 300, 400);
    userDialog.setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE);
    userDialog.setVisible(true);
    }
    }
      

  8.   

    这只是没修饰过的界面,如果图片做的好,界面就可以很漂亮。可以把图片路径塞给上面代码里的File构造函数。
      

  9.   

    swing漂亮到挺郁闷
    你看oracle的界面 难看死了!
    哎  悲哀!