我想在java中创建桌面应用程序,横幅/工具栏(我在netbeans中使用swing),我希望它与windows任务栏相同,意味着桌面图标将根据横幅位置重新排列。< / p>
怎么做?
感谢您的回复。
答案 0 :(得分:1)
其中一种方法是使用JWindow
或Modal和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() {
}
}
答案 1 :(得分:1)
您需要使用Windows API,为此您需要使用Java Native Interface(JNI)。
最好的方法是使用C或C ++创建DLL(使用标题窗口)并将其导入Java代码。