Is it possible to build custom GUI like this in Java?

后端 未结 10 2039
独厮守ぢ
独厮守ぢ 2021-02-05 18:30

I made this in Photoshop and I plan to use it for my file sharing application:

I was wondering if it was possible to create GUI for my application that is gonna

相关标签:
10条回答
  • 2021-02-05 18:35

    I have to disagree with you! Actually you can use NetBeans to create such a GUI. It is easy too, you have a lot of options to work with! The ones I personally use are:

    1) Create graphics with a painting software, and set it as Icon to the component. I use for the designing process InkScape, but any software should do the trick. You have to be preatty careful in this process, becouse you can't resize images in NetBeans (well, I never tried).

    2) extend the UI class (Example: public class CustomButtonUI extend BasicButtonUI), and override the method paint, then use the function setUI (componentName.setUI(new CustomButtonUI);)

    This is an example code:

    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Rectangle;
    import javax.swing.AbstractButton;
    import javax.swing.JComponent;
    import javax.swing.plaf.basic.BasicButtonUI;
    
    /**
     *
     * @author Ionut Cicio
     */
    public class CustomButton extends BasicButtonUI{
    
        int borderThickness, edgeRoundness;
    
        @Override
        public void paint(Graphics g, JComponent c) {
            Graphics2D g2 = (Graphics2D)g;
            g2.setColor(c.getBackground());
    
            borderThickness = 2;
            edgeRoundness = 20;
    
            g2.setColor(c.getForeground());
            g2.fillRoundRect(0, 0, c.getWidth(), c.getHeight(), edgeRoundness+5, edgeRoundness+5);
            g2.drawRoundRect(0, 0, c.getWidth(), c.getHeight(), edgeRoundness+5, edgeRoundness+5);
            //g2.fillRect(0, 0, c.getWidth(), c.getHeight());
            //g2.drawRect(0, 0, c.getWidth(), c.getHeight());
    
            g2.setColor(c.getBackground());
            g2.fillRoundRect(borderThickness, borderThickness, c.getWidth()-(int)(borderThickness*2.5), c.getHeight()-(int)(borderThickness*2.5), edgeRoundness, edgeRoundness);
            g2.drawRoundRect(borderThickness, borderThickness, c.getWidth()-(int)(borderThickness*2.5), c.getHeight()-(int)(borderThickness*2.5), edgeRoundness, edgeRoundness);
    
            super.paint(g, c);
        }
    
        @Override
        protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect) {
    
        }
    }
    

    It always happens to use both methods together, and it gives you a really big benefit whe working on animations!

    For some kinds of UI's as BasicTextFieldUI, understanding how painting works is preatty tricky, but still understandable.

    0 讨论(0)
  • 2021-02-05 18:43

    It's possible. But for most Java developers, it would require suppressing the gag reflex at such an ugly interface.

    Here's a Java interface I wrote using no tools other than vi. I didn't design it, I just took the artists design, held my nose, and implemented it.

    As for specifics, I'd suggest doing as much of the look and feel through the pluggable look and feel in Swing. Also, use LayoutManagers rather than making things constant sizes in constant locations, so that things can grow and shrink to different screen resolutions and also so that if you translate things you don't end up having to resize all your text labels and then shuffling everything else around.

    0 讨论(0)
  • 2021-02-05 18:43

    You'll have to create a lot of custom JComponents. Other than that, possible.

    0 讨论(0)
  • 2021-02-05 18:46

    It is very possible using Swing.

    Check out the NetBeans GUI Builder

    0 讨论(0)
  • 2021-02-05 18:46

    I would recommend

    MiG Layout

    for laying out components, it's very easy to grasp and is also way more powerful than the standard layout managers (and it's got a nice debugging mode, too).

    0 讨论(0)
  • 2021-02-05 18:50

    Creating new LaF is too much. Since all your JButtons are different, just use JButton.setIcon() and JButton.setPressedIcon() and use your images. The rest is loading background and using strange fonts. Use Font.createFont() to load custom fonts. You'll probably have to draw your own JProgressbar. Override JProgressBar.paintComponent(Graphics g) and draw your own image.

    0 讨论(0)
提交回复
热议问题