कैसे कर सकते हैं मैं सही ढंग से JComponent (रों) से XxxSize रिटर्न को जोड़ा गया JLabelकैसे JComponent से XxxSize रिटर्न (रों) JLabel
1 को जोड़ा गया। आंकड़ा >>lets LayoutManager works like as for JPanel, JLabel returns Size(0, 0)
2। आंकड़ा >>added some PreferredSize to the JLabel
3। आंकड़ा >>calculated PreferredSize from JComponent(s) added to the JLabel
4। आंकड़ा >>lets LayoutManager works changed JLabel to JPanel, now LayoutManager correctly calculated Dimension without using any XxxSize
नोटिस साईस वहाँ प्रयोग किया जाता है निंबस एल & एफ, एक ही आउटपुट सब नहीं पहुंच एल के लिए है & एफ
import java.awt.*;
import java.awt.event.*;
import java.util.LinkedList;
import java.util.Queue;
import javax.swing.*;
public class NimbusBorderPainterDemo extends JFrame {
private static final long serialVersionUID = 1L;
private JFrame frame = new JFrame();
private JPanel fatherPanel = new JPanel(), titlePanel = new JPanel();
private JLabel buttonPanel = new JLabel();
//figure ---> 4th. switch JLabel with JPanel
//private JPanel buttonPanel = new JPanel();
private Queue<Icon> iconQueue = new LinkedList<Icon>();
public NimbusBorderPainterDemo() {
iconQueue.add(UIManager.getIcon("OptionPane.errorIcon"));
iconQueue.add(UIManager.getIcon("OptionPane.informationIcon"));
iconQueue.add(UIManager.getIcon("OptionPane.warningIcon"));
JButton button0 = createButton();
JButton button1 = createButton();
JButton button2 = createButton();
button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(1);
}
});
int gap = 5;
buttonPanel.setLayout(new GridLayout(0, 3, gap, 0));
buttonPanel.add(button0);
buttonPanel.add(button1);
buttonPanel.add(button2);
// figure 1st. ---> without PreferredSize
// figure 2nd. --->
//buttonPanel.setPreferredSize(new Dimension(160, 30));
// figure 3rd. --->
/*Dimension dim = button0.getPreferredSize();
int w = dim.width;
int h = dim.height;
w = (w + 5) * 3;
h += 4;
dim = new Dimension(w, h);
buttonPanel.setPreferredSize(dim);*/
titlePanel.setLayout(new BorderLayout());
titlePanel.add(new JLabel(nextIcon()), BorderLayout.WEST);
titlePanel.add(new JLabel("My Frame"), BorderLayout.CENTER);
titlePanel.setBorder(BorderFactory.createLineBorder(Color.GRAY));
titlePanel.add(buttonPanel, BorderLayout.EAST);
fatherPanel.setLayout(new BorderLayout());
fatherPanel.add(titlePanel, BorderLayout.CENTER);
frame.setUndecorated(true);
frame.add(fatherPanel);
frame.setLocation(50, 50);
frame.pack();
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
frame.setVisible(true);
}
private JButton createButton() {
JButton button = new JButton();
button.setBorderPainted(false);
button.setBorder(null);
button.setFocusable(false);
button.setMargin(new Insets(0, 0, 0, 0));
button.setContentAreaFilled(false);
button.setIcon(nextIcon());
//button.setRolloverIcon(nextIcon());
//button.setPressedIcon(nextIcon());
//button.setDisabledIcon(nextIcon());
nextIcon();
return button;
}
private Icon nextIcon() {
Icon icon = iconQueue.peek();
iconQueue.add(iconQueue.remove());
return icon;
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (Exception fail) {
}
UIManager.getLookAndFeelDefaults().put("nimbusFocus", Color.RED);
NimbusBorderPainterDemo nimbusBorderPainterDemo = new NimbusBorderPainterDemo();
}
});
}
}
+1 अच्छा सवाल है, लेकिन 'बटन पैनेल' को 'जेलाबेल' क्यों बनाते हैं? – trashgod
@trashgod क्योंकि 1) संभव नहीं है सभी के लिए अस्पष्टता या पारदर्शिता जानता है और महसूस करता है, उदाहरण के लिए निंबस का उपयोग करके एक और वुडू की आवश्यकता होती है, 2) मैंने तकनीकी रूप से संभव होने पर जेएलएबल – mKorbel
पर आधारित अच्छा पॉपअप फैक्ट्री देखा, यह उपयोग करना आसान है JLabel कंटेनर के रूप में ... – kleopatra