Set Font for Text in JTextPane with Java

Arjun Thakur
Updated on 30-Jul-2019 22:30:26

1K+ Views

Use the Font class to set font for text. Let us first create JTextPane component −JTextPane textPane = new JTextPane();Now, set the font with the Font class setFont() method −Font font = new Font("Serif", Font.ITALIC, 18); textPane.setFont(font);The following is an example to set font for text −Examplepackage my; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTextPane; import javax.swing.text.BadLocationException; import javax.swing.text.SimpleAttributeSet; import javax.swing.text.Style; import javax.swing.text.StyleConstants; import javax.swing.text.StyledDocument; public class SwingDemo {    public static void main(String args[]) throws BadLocationException {       JFrame frame = new JFrame("Demo");       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       ... Read More

Delete Entry in MySQL

Ankith Reddy
Updated on 30-Jul-2019 22:30:26

139 Views

You can use delete command −delete from yourTableName where yourColumnName='\\';Let us first create a table −mysql> create table DemoTable    (    FolderName varchar(100)    ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values("????"); Query OK, 1 row affected (0.44 sec) mysql> insert into DemoTable values("\\"); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+------------+ | FolderName | +------------+ | ???? | | \ ... Read More

Group By a Column in Another MySQL Table

Rama Giri
Updated on 30-Jul-2019 22:30:26

358 Views

For this, you can use CREATE TABLE AS SELECT statement. Let us first create a table −mysql> create table DemoTable1    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> CountryName varchar(20)    -> ); Query OK, 0 rows affected (0.68 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1(CountryName) values('US'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1(CountryName) values('UK'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable1(CountryName) values('AUS'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1(CountryName) values('UK'); Query OK, ... Read More

C++ Program for Largest K-Digit Number Divisible by X

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

174 Views

In this problem we will try to find largest K-digit number, that will be divisible by X. To do this task we will take the largest K digit number by this formula ((10^k) – 1). Then check whether the number is divisible by X or not, if not, we will get the exact number by using this formula.𝑚𝑎𝑥−(𝑚𝑎𝑥 𝑚𝑜𝑑 𝑋)One example is like a 5-digit number, that is divisible by 29. So the largest 5-digit number is 99999. This is not divisible by 29. Now by applying the formula we will get −99999−(99999 𝑚𝑜𝑑 29)=99999−7=99992The number 99992 is divisible by ... Read More

fesetround and fegetround in C++

Anvi Jain
Updated on 30-Jul-2019 22:30:26

143 Views

Here we will see the fesetround() and fegetround() method in C++. These methods can be found in the cfenv library.The fesetround() method is used to set the specified floating point rounding direction to the current rounding direction. This is used with rint(), nearbyint() and some other rounding functions in C++.The syntax is like below −int fesetround(int round);The round can be among these FE_TONEAREST, FE_DOWNWARD, FE_UPWARD etc. This function returns 0 when rounding direction is successfully applied to the required manner.Example#include #include #include using namespace std; main() {    double x = 4.7, ans;    fesetround(FE_TONEAREST); //round to ... Read More

Count Rows in Java

Vikyath Ram
Updated on 30-Jul-2019 22:30:26

10K+ Views

The SQL Count() function returns the number of rows in a table. Using this you can get the number of rows in a table.select count(*) from TABLE_NAME;Let us create a table with name cricketers_data in MySQL database using CREATE statement as shown below −CREATE TABLE cricketers_data(    First_Name VARCHAR(255),    Last_Name VARCHAR(255),    Date_Of_Birth date,    Place_Of_Birth VARCHAR(255),    Country VARCHAR(255), );Now, we will insert 5 records in cricketers_data table using INSERT statements −insert into cricketers_data values('Shikhar', 'Dhawan', DATE('1981-12-05'), 'Delhi', 'India'); insert into cricketers_data values('Jonathan', 'Trott', DATE('1981-04-22'), 'CapeTown', 'SouthAfrica'); insert into cricketers_data values('Kumara', 'Sangakkara', DATE('1977-10-27'), 'Matale', 'Srilanka'); insert into cricketers_data values('Virat', 'Kohli', DATE('1988-11-05'), 'Delhi', ... Read More

Insert MongoDB Document Field Only When It's Missing

Smita Kapse
Updated on 30-Jul-2019 22:30:26

345 Views

Let us first create a collection with documents −>db.missingDocumentDemo.insertOne({"StudentFirstName":"Adam", "StudentLastName":"Smith"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd3fb1eedc6604c74817ce6") } >db.missingDocumentDemo.insertOne({"StudentFirstName":"Carol", "StudentLastName":"Taylor"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd3fb29edc6604c74817ce7") } >db.missingDocumentDemo.insertOne({"StudentFirstName":"David", "StudentLastName":"Miller", "StudentAge":21}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd3fb40edc6604c74817ce8") }Following is the query to display all documents from a collection with the help of find() method −> db.missingDocumentDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cd3fb1eedc6604c74817ce6"),    "StudentFirstName" : "Adam",    "StudentLastName" : "Smith" } {    "_id" : ObjectId("5cd3fb29edc6604c74817ce7"),    "StudentFirstName" : "Carol",    "StudentLastName" : "Taylor" } {    "_id" : ... Read More

Disable Only the Vertical Scrollbar in Java

Smita Kapse
Updated on 30-Jul-2019 22:30:26

1K+ Views

To disable only the vertical scrollbar, use the VERTICAL_SCROLLBAR_NEVER constant, which displays only the horizontal scrollbar.The following is an example to disable only the vertical scrollbar in Java −Examplepackage my; import java.awt.BorderLayout; import java.awt.Dimension; import javax.swing.Box; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JScrollPane; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Demo");       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       JButton button1 = new JButton("Online Compiler");       JButton button2 = new JButton("Quiz");       JButton button3 = new JButton("Questions and Answers");       JButton button4 = new JButton("Videos"); ... Read More

Move First Row to End of JTable in Java Swing

Chandu yadav
Updated on 30-Jul-2019 22:30:26

672 Views

To move the first row to the end of the table in Java, use the moveRow() method. It has three parameters. The first two parameters allows you to set the starting and ending row index to be moved. The last parameter sets the destination of the rows to be moved.As discussed above, move the first row to the end −tableModel.moveRow(0, 0, tableModel.getRowCount() - 1);The following is an example to move the first row to the end of the table −Examplepackage my; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; public class SwingDemo {    public static void main(String[] argv) throws ... Read More

Batch Inserts Using JDBC Prepared Statements

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

6K+ Views

Grouping a set of INSERT Statements and executing them at once is known as batch insert.Batch inserts using PreparedStatement objectTo execute a batch of insert statements using the PreparedStatement object −Create a PreparedStatement − Create a PreparedStatement object using the prepareStatement() method. Pass the Insert query with place holders “?” instead of values as a parameter to this method.PreparedStatement pstmt = con.prepareStatement("INSERT INTO Sales VALUES (?, ?, ?, ?, ?)");Set the values to the place holders − Using the setXXX() methods (setInt(). SetString(), setFloat() etc…) set the values to the place holders in the PrepareStatement as −pstmt.setString(1, "KeyBoard"); pstmt.setString(2, "Amith"); ... Read More

Advertisements