每當我運行應用程序,JFrame中和它的工具欄使用 L尺寸指定& F(靈氣),但內部框架採用跨平臺 (金屬)長&˚F使應用程序顯得寒酸。
import java.awt.Dimension;
import java.awt.EventQueue;
import javax.swing.*;
import javax.swing.UIManager.LookAndFeelInfo;
public class TestInternalFrame {
public TestInternalFrame() {
final JInternalFrame internal = new JInternalFrame("test");
final JInternalFrame hidden = new JInternalFrame("test");
hidden.setBounds(1000, 1000, 1, 1);
hidden.setVisible(true);
internal.setVisible(true);
internal.setBounds(0, 0, 100, 100);
JDesktopPane pane = new JDesktopPane();
pane.add(internal);
pane.add(hidden);
pane.setPreferredSize(new Dimension(10000, 10000));
final JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.getContentPane().add(new JScrollPane(pane,
JScrollPane.VERTICAL_SCROLLBAR_NEVER,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER));
/*frame.getContentPane().add(new JButton(new AbstractAction("Show blocked dialog") {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent e) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
JOptionPane.showInternalMessageDialog(hidden, "Hi 2!");
}
});
JOptionPane.showInternalMessageDialog(internal, "Hi 1!");
}
}), BorderLayout.PAGE_END);*/
frame.setPreferredSize(new Dimension(400, 300));
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
System.out.println(info.getName());
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (UnsupportedLookAndFeelException e) {
// handle exception
} catch (ClassNotFoundException e) {
// handle exception
} catch (InstantiationException e) {
// handle exception
} catch (IllegalAccessException e) {
// handle exception
}
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
TestInternalFrame tif = new TestInternalFrame();
}
});
}
}
1)爲了更好地幫助越早,張貼[ SSCCE](http://sscce.org/)。 2)*「我嘗試過調用'SwingUtilities.updatecomponenttreeui(frame)',但它們沒有解決問題。」*那不會編譯。 –
@AndrewThompson我的意思是JFrame.setDefaultLookAndFeelDecorated(true)和SwingUtilities.updateComponentTreeUi(框架)。代碼編譯但不解決問題。 –
很好,你注意到了第二點。現在參加第一場。 ;) –