大佬教程收集整理的这篇文章主要介绍了Java:如何控制JPanel长宽比?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
您可以使用@H_403_1@GrIDBagLayout和@H_403_1@ComponentListener,
例如:(启发自:https ://community.Oracle.com/thread/1265752?start=0&tstart=0)
@H_403_1@public class AspectRatio { public static voID main(String[] args) { final JPanel innerPanel = new JPanel(); innerPanel.setBACkground(color.YELLOW); final JPanel container = new JPanel(new GrIDBagLayout()); container.add(innerPanel); container.addComponentListener(new ComponentAdapter() { @OverrIDe public voID componentResized(ComponentEvent E) { resizePrevIEw(innerPanel, container); } }); final JFrame frame = new JFrame("AspectRatio"); frame.getContentPane().add(container); frame.setDefaultCloSEOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(600, 600); frame.setVisible(true); } private static voID resizePrevIEw(JPanel innerPanel, JPanel container) { int w = container.getWIDth(); int h = container.getHeight(); int size = Math.min(w, h); innerPanel.setPreferredSize(new Dimension(size, sizE)); container.revalIDate(); } }
以上是大佬教程为你收集整理的Java:如何控制JPanel长宽比?全部内容,希望文章能够帮你解决Java:如何控制JPanel长宽比?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。