我想創建桌面應用程序的Java旗幟/工具欄,橫幅/工具欄,在Java(我使用的擺動在NetBeans),我希望它起到相同Windows任務欄上,意味着桌面圖標將根據橫幅位置重新排列。創建像個Windows任務欄
如何做?
感謝您的回覆。
我想創建桌面應用程序的Java旗幟/工具欄,橫幅/工具欄,在Java(我使用的擺動在NetBeans),我希望它起到相同Windows任務欄上,意味着桌面圖標將根據橫幅位置重新排列。創建像個Windows任務欄
如何做?
感謝您的回覆。
的方法之一是使用JWindow
或模態和un_decorated JDialog
,例如
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JWindow;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
public class SlideText_1 {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
createAndShowGUI();
}
});
}
private static void createAndShowGUI() {
final JWindow window = new JWindow();
final JPanel windowContents = new JPanel();
JLabel label = new JLabel("A window that is pushed into view..........");
windowContents.add(label);
window.add(windowContents);
window.pack();
window.setLocationRelativeTo(null);
final int desiredWidth = window.getWidth();
window.getContentPane().setLayout(null);
window.setSize(0, window.getHeight());
window.setVisible(true);
Timer timer = new Timer(15, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int newWidth = Math.min(window.getWidth() + 1, desiredWidth);
window.setSize(newWidth, window.getHeight());
windowContents.setLocation(newWidth - desiredWidth, 0);
if (newWidth >= desiredWidth) {
((Timer) e.getSource()).stop();
window.getContentPane().setLayout(new BorderLayout()); //restore original layout
window.validate();
window.setVisible(false);
}
}
});
timer.start();
}
private SlideText_1() {
}
}
沙哈爾問這個問題,我的名義。我認爲可以用純Java來完成,但據我所知,在這種情況下,Java是一個死衚衕。
您需要使用Windows API,併爲您將需要使用Java本地接口(JNI)。
最好的方法是使用C或C++(使用頭窗口)創建一個DLL並將其導入到Java代碼中。
事情是,它只是懸停在桌面項目上方,我希望桌面項目(圖標等)對橫幅作出反應並且不會與其發生衝突。 – 2012-03-14 12:03:53