应用投影的最佳方法是什么?(What's the best way to apply a drop shadow?)
应用阴影的最佳方法是什么? 我现在在一个网站上工作,我们有很多它们,但是,我一直在努力寻找最好的方法来做到这一点。 该网站的动画很重,因此阴影需要与此配合良好。
我尝试了一个jQuery阴影pulgin。 阴影看起来很好并且易于使用,但速度很慢,并且不适用于任何动画(需要大量重绘,非常慢跑)。
我也尝试创建自己的jQuery扩展,将我的元素包装在几个灰色的div中,然后稍微偏移它们以产生阴影效果。 这很好用。 它对动画的快速响应。 然而,它使得DOM操作/遍历变得麻烦,因为所有内容都包含在这些阴影div中。
我知道必须有一个更好的方法,但这不完全是我的强项。 思考?
What is the best method for applying drop shadows? I'm working on a site right now where we have a good deal of them, however, I've been fighting to find the best method to do it. The site is pretty animation heavy so shadows need to work well with this.
I tried a jQuery shadow pulgin. The shadows looked good and were easy to use but were slow and didn't work well with any animations (required lots of redrawing, very joggy).
I also tried creating my own jQuery extension that wraps my element in a couple gray divs and then offsets them a little bit to give a shadow effect. This worked well. It's quick and responsive to the animation. However, it makes DOM manipulation/traversal cumbersome since everything is wrapped in these shadow divs.
I know there has to be a better way but this isn't exactly my forte. Thoughts?
原文:https://stackoverflow.com/questions/239816
最满意答案
在将Panel添加到
FinestradiRicerca
之前,您需要将新元素添加到riquadroRicerca
,我建议您不要使用null
布局,而是使用布局管理器或它们的组合。 如果您坚持保留null布局,请参阅下面的示例。 但对于这种应用程序,我建议使用CardLayout
。我还建议不要使用多个
JFrames
因为它们会在用户不友好的任务栏上打开多个窗口。 请参阅: 使用多个JFrame,好/坏练习另外,请遵循Java命名约定 。 例如,您将
JFrame
称为FinestradiRicerca
而是将其重命名为:finestradiRicerca
( 变量的第一个字母为小写)。import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class MainWindow { // Seconda Finestra public static void NuovaFinestra (JPanel panel) { panel.setLayout(null); JButton Ricerca = new JButton("Ricerca"); Ricerca.setBounds(100, 100, 200, 50); panel.add(Ricerca); Ricerca.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { JFrame FinestradiRicerca = new JFrame("Finestra di Ricerca"); FinestradiRicerca.setBounds(300, 300, 500, 500); //If you don't want to close whole app when closing this windo change it to: JFrame.DISPOSE_ON_CLOSE FinestradiRicerca.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel riquadroRicerca = new JPanel(); JTextField ciao; JLabel myLabel = new JLabel("Here goes your label text"); ciao = new JTextField (); ciao.setColumns(20); riquadroRicerca.add(myLabel); riquadroRicerca.add(ciao); FinestradiRicerca.add(riquadroRicerca); FinestradiRicerca.setVisible(true); } }); } //Main public static void main(String[] args) { //Finestra Principale JFrame finestra = new JFrame("Finestra principale"); finestra.setSize(500, 500); finestra.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //JPanel della finestra principale JPanel riquadro = new JPanel(); finestra.add(riquadro); finestra.setVisible(true); NuovaFinestra(riquadro); } }
因此,经过一些修改后,为了使
JLabel
和JTextField
可见,您的代码将提供以下输出:但请遵循我的上述建议。
You needed to add your new elements to
riquadroRicerca
BEFORE adding the Panel toFinestradiRicerca
, I recommend you NOT to usenull
layout but a Layout Manager or combinations of them. If you insist on keeping null layout then see below example. But for this kind of app I'd suggest aCardLayout
.I also suggest not using multiple
JFrames
since they will open multiple windows on task bar which is user unfriendly. See: Use of multiple JFrames, Good / Bad PracticeAs an aside note, follow Java naming conventions. For example you called a
JFrame
asFinestradiRicerca
instead rename it to:finestradiRicerca
(1st letter of a variable in lowercase).import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class MainWindow { // Seconda Finestra public static void NuovaFinestra (JPanel panel) { panel.setLayout(null); JButton Ricerca = new JButton("Ricerca"); Ricerca.setBounds(100, 100, 200, 50); panel.add(Ricerca); Ricerca.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { JFrame FinestradiRicerca = new JFrame("Finestra di Ricerca"); FinestradiRicerca.setBounds(300, 300, 500, 500); //If you don't want to close whole app when closing this windo change it to: JFrame.DISPOSE_ON_CLOSE FinestradiRicerca.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel riquadroRicerca = new JPanel(); JTextField ciao; JLabel myLabel = new JLabel("Here goes your label text"); ciao = new JTextField (); ciao.setColumns(20); riquadroRicerca.add(myLabel); riquadroRicerca.add(ciao); FinestradiRicerca.add(riquadroRicerca); FinestradiRicerca.setVisible(true); } }); } //Main public static void main(String[] args) { //Finestra Principale JFrame finestra = new JFrame("Finestra principale"); finestra.setSize(500, 500); finestra.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //JPanel della finestra principale JPanel riquadro = new JPanel(); finestra.add(riquadro); finestra.setVisible(true); NuovaFinestra(riquadro); } }
So, your code after a few modifications, to make
JLabel
andJTextField
visible gives the following output:However, please follow my above recomendations.
相关问答
更多-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
查看Text Prompt以获得灵活的解决方案。 您可以控制何时显示提示(始终提高焦点或减少焦点)。 您还可以自定义文本的样式。 Check out Text Prompt for a flexible solution. You can control when prompt is displayed (always, focus gained or focus lost). You can also customize the style of the text.
-
这是因为你没有使用任何我建议使用FlowLayout和GridBagLayout的布局。 It's because you are not using any layout I suggest to use FlowLayout and GridBagLayout.
-
编辑, 只有在屏幕上显示其父级时, JWindow内容才可访问 对于可编辑和可访问的内容,使用un_decorated JDialog而不是JWindow ,jDialog不会导致不可访问的内容, 之所以......,我无法解释,没有找不到原因,在这一刻没有办法,API没有告诉我什么导致可访问,可编辑...... 。 。 。 1. Why JTextField is uneditable in JWindow and how could i let it able to edit? 真的不知道 impor ...
-
自动出现JTextField(Appear automatically JTextField)[2023-01-07]
就像我刚才提到的,这对于你的问题是一个简单的方法。 首先创建所需的所有JTextField,并切换其可见性,而不是在运行时删除和添加它。 import java.util.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; class DynamicTextFieldsApp { public static void main(String[] args){ javax.swing.SwingUt ... -
在将Panel添加到FinestradiRicerca之前,您需要将新元素添加到riquadroRicerca ,我建议您不要使用null布局,而是使用布局管理器或它们的组合。 如果您坚持保留null布局,请参阅下面的示例。 但对于这种应用程序,我建议使用CardLayout 。 我还建议不要使用多个JFrames因为它们会在用户不友好的任务栏上打开多个窗口。 请参阅: 使用多个JFrame,好/坏练习 另外,请遵循Java命名约定 。 例如,您将JFrame称为FinestradiRicerca而是将其重 ...
-
如何将JTextField从JFrame传递到另一个JFrame?(How to pass JTextField from JFrame into another JFrame?)[2023-09-05]
您可以使用观察者模式或生产者/消费者模式来解决问题。 基本的想法是,你有一些产生价值的东西,或者想要被通知或消耗所产生的价值的东西。 您应该花时间学习的其他原则之一也是Code to interface(而不是实现) 。 这听起来很奇怪,但其目的是减少对象的不必要暴露(对非预期/受控的修改)并解耦代码,这样您就可以更改底层实现,而不会影响依赖它的任何其他代码 鉴于您的问题的性质,观察者模式可能更合适。 Swing的大多数听众都是基于同样的原则。 我们首先定义“生成器”将用于提供变更通知的合同...... p ... -
默认情况下, JFrame永远不会对KeyEvent做出反应,这意味着frame.setFocusable(true); 必须为JPanel设置setFocusable(true) ,然后KeyListener KeyEvents将触发所需的事件 不要将KeyListener用于Swing JComponent ,而是使用(大多数可伸缩,可设置的) KeyBindings ( 例如 ) 对BorderLayout使用常量 ,只能看到一个JComponent ,放在第5个中。 区 JFrame by defa ...
-
如果需要两个单独的字段,则需要有两个单独的JTextField对象:尝试添加 JTextField field2 = new JTextField("Your second field"); 并将您frame上的第一个add()调用更改为 frame.add(BorderLayout.NORTH, field2); 这将产生 我认为是你想要的。 You need to have two seperate JTextField objects if you want two seperate fields ...
-
来自另一个JFrame的JTextField中的setText()无法使用(unable setText() in JTextField from another JFrame)[2022-01-09]
如果您“不想再次打开第一帧”,则必须避免先创建新实例并使用之前实例的引用。 所以你需要一个引用...给你的第二个引用的第一种方法是在构造函数中提供它,如: private void jButton1ActionPerformed(java.awt.event.ActionEvent evt){ second sec = new second(this); //notice I'm passing a reference ...